I have a Meteor app with a server folder; in that server folder, I added a .js file with this content:
PostTravel = new Mongo.Collection('postTravel');
if (PostTravel.find().count() === 0) {
PostTravel.insert({
title: 'Introducing Telescope',
url: 'http://sachagreif.com/introducing-telescope/'
});
PostTravel.insert({
title: 'Meteor',
url: 'http://meteor.com'
});
PostTravel.insert({
title: 'The Meteor Book',
url: 'http://themeteorbook.com'
});
}
Note: I adapted this code from here: http://es.discovermeteor.com/chapters/collections/
When Meteor tries to run this new code, though, it fails, telling me, âReferenceError: PostTravel is not defined â
Here is a dump of the pertinent communique from the command prompt:
C:\Users\clayshan\Meteor\posttravel>meteor
=> Started proxy.
=> Started MongoDB.
=> Exited with code: 8
W20150812-11:27:35.357(-7)? (STDERR)
W20150812-11:27:35.362(-7)? (STDERR) C:\Users\clayshan\AppData\Local\.meteor\pac
kages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\
fibers\future.js:245
W20150812-11:27:35.363(-7)? (STDERR)
throw(ex);
W20150812-11:27:35.363(-7)? (STDERR)
^
W20150812-11:27:45.686(-7)? (STDERR) ReferenceError: PostTravel is not defined
W20150812-11:27:45.687(-7)? (STDERR) at app\server\loaddata.js:1:40
W20150812-11:27:45.687(-7)? (STDERR) at app\server\loaddata.js:18:3
W20150812-11:27:45.687(-7)? (STDERR) at C:\Users\clayshan\Meteor\posttravel\
.meteor\local\build\programs\server\boot.js:222:10
W20150812-11:27:45.687(-7)? (STDERR) at Array.forEach (native)
W20150812-11:27:45.688(-7)? (STDERR) at Function._.each._.forEach (C:\Users\
clayshan\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\d
ev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
W20150812-11:27:45.688(-7)? (STDERR) at C:\Users\clayshan\Meteor\posttravel\
.meteor\local\build\programs\server\boot.js:117:5
=> Exited with code: 8
So what am I doing wrong here?
Youâre likely referencing PostTravel in the loaddata.js file before itâs had a chance to load. You might want to consider moving your Collection definition into the lib directory. See http://docs.meteor.com/#/full/fileloadorder for more details.
Thanks, that did it; âtiming is everything.â - Clay ShannonMark Twain Central
sissi
June 7, 2018, 8:44am
4
this doesnât work for me. I have the same problem, my collections are ânot definedâ despite me putting them in a collection.js file in the lib folder (which has worked several times before!) suddenly it doesnât, have tried re-installing meteor, anyone any idea?
thanks in advance
Please share your folder structure.
sissi
June 7, 2018, 9:15am
6
itâs actually a standard app created by âmeteor createâ. only added a âlibâ folder with only the âcollections.jsâ in there.
so itâs
.meteor
client
lib
node_modules
server
test
havenât edited any file besides collections etiher, and if i try âCards.find().fetch()â or even only âCardsâ which is my collection in the console, it reveals the error message.
i also tried to rename âlibâ to âcollectionsâ because i saw that in some tutorials, but it (unsurprisingly) didnt change anything
What version of Meteor are you using?
And, are you using import/export
syntax?
sissi
June 7, 2018, 9:21am
8
iâve only just reinstalled it as a try to fix the issue, so i have 1.7.0.1 now. so far, i only have the import statements which the standard app comes with and in my collection.js i have
import { Mongo } from âmeteor/mongoâ;
Cards = new Mongo.Collection(âcardsâ);
A new project created with Meteor 1.7 will use the new default lazy-loading, in which all files need specific import
statements.
To restore âclassicâ behaviour, you will need to edit the package.json
from this:
{
"name": "mytest",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.48",
"meteor-node-stubs": "^0.4.1"
},
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "test/main.js"
}
}
to this:
{
"name": "mytest",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.48",
"meteor-node-stubs": "^0.4.1"
}
}
In other words, remove the meteor
stanza.
1 Like
sissi
June 7, 2018, 9:37am
10
Thank you!
I tried this, and now it says
W20180607-11:35:32.435(2)? (STDERR) C:\Users\administrator\AppData\Local.meteor\packages\meteor-tool\1.7.0_1\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
W20180607-11:35:32.437(2)? (STDERR) throw(ex);
W20180607-11:35:32.438(2)? (STDERR) ^
W20180607-11:35:32.438(2)? (STDERR)
W20180607-11:35:32.439(2)? (STDERR) Error: Cannot find module â./main.htmlâ
W20180607-11:35:32.439(2)? (STDERR) at makeMissingError (packages\modules-runtime.js:231:12)
W20180607-11:35:32.440(2)? (STDERR) at require (packages\modules-runtime.js:241:19)
W20180607-11:35:32.440(2)? (STDERR) at collections.js (collections/collections.js:1:193)
W20180607-11:35:32.441(2)? (STDERR) at fileEvaluate (packages\modules-runtime.js:339:7)
W20180607-11:35:32.441(2)? (STDERR) at require (packages\modules-runtime.js:238:16)
W20180607-11:35:32.442(2)? (STDERR) at C:\Users\administrator\Desktop\Neuer Ordner\mem.meteor\local\build\programs\server\app\app.js:132:1
W20180607-11:35:32.442(2)? (STDERR) at C:\Users\administrator\Desktop\Neuer Ordner\mem.meteor\local\build\programs\server\boot.js:411:36
W20180607-11:35:32.442(2)? (STDERR) at Array.forEach ()
W20180607-11:35:32.443(2)? (STDERR) at C:\Users\administrator\Desktop\Neuer Ordner\mem.meteor\local\build\programs\server\boot.js:220:19
W20180607-11:35:32.443(2)? (STDERR) at C:\Users\administrator\Desktop\Neuer Ordner\mem.meteor\local\build\programs\server\boot.js:471:5
W20180607-11:35:32.444(2)? (STDERR) at Function.run (C:\Users\administrator\Desktop\Neuer Ordner\mem.meteor\local\build\programs\server\profile.js:510:12)
W20180607-11:35:32.444(2)? (STDERR) at C:\Users\administrator\Desktop\Neuer Ordner\mem.meteor\local\build\programs\server\boot.js:470:11
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.
Did you forget to do meteor npm i
first?
Also, I forgot to mention that restoring classic behaviour means you will get other errors if you leave the test/
folder there, so delete it, or move it into imports/
, or rename it to .test/
.
sissi
June 7, 2018, 9:57am
12
thank you, everything is fixed now! canât believe i forgot to edit package.json, has been a while since iâve started a meteor project from scratchâŚ
thanks so much!
1 Like
Youâre welcome.
Incidentally, Iâve raised an issue about the test
folder behaviour.
robfallows:
A new project created with Meteor 1.7 will use the new default lazy-loading, in which all files need specific import
statements.
To restore âclassicâ behaviour, you will need to edit the package.json
from this:
{
"name": "mytest",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.48",
"meteor-node-stubs": "^0.4.1"
},
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "test/main.js"
}
}
to this:
{
"name": "mytest",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.48",
"meteor-node-stubs": "^0.4.1"
}
}
In other words, remove the meteor
stanza.
thank you, this solved quite a bit of things for me
1 Like