Reputation: 63647
superpack
is an npm package that is warped using _wrapAsync
. Why does inserting into the collection UserSession
cause an error stating that the collection is not defined?
server/helpers/b.js
// Init
var SUPERPACK = Meteor.require('superpack');
var superpack = SUPERPACK(a,b);
// Get Info
superpack.getInfoSync = Meteor._wrapAsync(superpack.getInfo.bind(superpack));
var data = superpack.getInfoSync();
UserSession.insert({
'account': data
});
collections/UserSession.js
UserSession = new Meteor.Collection('user_sessions');
Error (server-side):
ReferenceError: UserSession is not defined
Meter v0.6.6.3 is used.
Upvotes: 2
Views: 445
Reputation: 75955
You have to be careful about file loading order. Deeply nested files load first (see Structuring your application in the meteor docs).
So your helpers are loading before before the collections js. Normally this is OK but it looks like you're inserting documents when Meteor starts up (i.e when not all the files have loaded yet).
I think you might have to put your tasks in a Meteor.startup(function() {..})
which runs when meteor starts up, the only difference is it does it after all the files have loaded.
Upvotes: 2