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

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!

1 Like

Please, anyone? :frowning:

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.

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.

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:

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!