Error: Cannot find module '/imports/api/donuts/collection.js'


#1

Hi,

I am having some trouble importing a module into the meteor shell.

Steps I follow are from the Meteor Tuts, right at the beginning:

  1. create new project (meteor create myproject)
  2. create file /imports/api/donuts/collection.js and paste content:
// file: /imports/api/donuts/collection.js
import { Mongo } from 'meteor/mongo';
const Donuts = new Mongo.Collection('donuts');
export default Donuts;

3, Run meteor shell and import the file by:


 import Donuts from '/imports/api/donuts/collection.js'

than this error hits up:

Error: Cannot find module '/imports/api/donuts/collection.js’
at Function.require.resolve (packages/modules-runtime.js:129:19)
at Module.resolve (packages/modules-runtime.js:81:25)
at Module.Mp.import (/home/ec2-user/.meteor/packages/modules/.0.7.7.mccaq7++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:61:29)
at repl:1:-37
at packages/shell-server/shell-server.js:458:25
at /home/ec2-user/.meteor/packages/promise/.0.8.8.i94065++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:32:39

What’s wrong? File permissions are ok, I start the meteor shell from project root.

Thanks!


#2

Please, anyone? :frowning:


#3

I am not sure I understand your question correctly. But your path to the collection is probably the issue.

Depending on where exactly you are trying to import your collection into, it should be something like:

import Donuts from ‘…/…/…/api/donuts’

each …/ navigates one folder out of the current folder.


#4

Hi. I am the creator of Meteor-Tuts and shame on me!
In my defence I only advertised it here and I specifically said it was not ready yet, it’s just a beta. But I’m glad it spread out :slight_smile:

Your feedback is great! Basically what you need to do, is your Meteor needs to be aware of that collection first. Otherwise it will not load everything by default

Go to /imports/startup/server/index.js. And just do :

import Donuts from '/imports/api/donuts/collection.js'

It will work. Today I’m finalizing the tutorial, and testing everything.


#5

Hehe, what a luck I have :smiley:

I am trying to get more familiar with the meteor shell, reason why I was following your tuts. I was so enthusiastic about working with imports inside the shell without including them elsewhere, but it turns out this step can’t be overcome. :frowning:

So it’s still need to include the collection.js in server/main.js. I am wondering why is the meteor shell bound to the process only, and not the whole project?

This limitation seems kinda weird to me. :confused:


#6

Hehe, I knew this would be an issue, I am now rewriting it to make it even more simple and introduce “Nasty Globals”, so we can use globals just for testing, I’ll put a big disclaimer discouraging it :smiley:

The reason is that Meteor compiles files it needs to know about, not everything. So if you never imported it anywhere, it won’t be available in Meteor shell.

I will update soon the tuts, to make it even more friendly for beginners. Will let you know here!