JoshJoe
JoshJoe

Reputation: 1640

Momentjs with Meteor doesn't seem to work on server side

I'm using the momentjs:moment package in my meteor project. Client side the moment(new Date()) call works great. If I do the same call on the server side or if I wrap the same call in console.log(moment(new Date())); I get the error at the bottom of this question.

If I run meteor shell and then moment(new Date()); I also get an error (moment is not defined). But if, from the shell, I wrap this in a console.log(moment(new Date())); it works fine and prints out to the console.

Any idea what I'm forgetting or what I'm not doing right here?

W20150318-19:55:45.885(-5)? (STDERR) TypeError: Property 'moment' of object #<Object> is not a function
    W20150318-19:55:45.885(-5)? (STDERR)     at Object._.extend.send_donation_email (app/server/methods/mandrill.js:37:25)
    W20150318-19:55:45.885(-5)? (STDERR)     at Object.Stripe_Events.charge.succeeded (app/server/lib/stripe_events.js:55:23)
    W20150318-19:55:45.885(-5)? (STDERR)     at [object Object].Router.route.where (app/both/router/router.js:238:48)
    W20150318-19:55:45.885(-5)? (STDERR)     at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1)
    W20150318-19:55:45.885(-5)? (STDERR)     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)
    W20150318-19:55:45.885(-5)? (STDERR)     at packages/meteor/dynamics_nodejs.js:121:1
    W20150318-19:55:45.885(-5)? (STDERR)     at [object Object].urlencodedParser (/Users/Bechard/.meteor/packages/iron_router/.1.0.7.1oysnq2++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:69:27)
    W20150318-19:55:45.885(-5)? (STDERR)     at packages/iron:router/lib/router.js:277:1
    W20150318-19:55:45.885(-5)? (STDERR)     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
    W20150318-19:55:45.885(-5)? (STDERR)     at [object Object].hookWithOptions (packages/iron:router/lib/router.js:276:1)
    W20150318-19:55:45.885(-5)? (STDERR)     at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1)
    W20150318-19:55:45.885(-5)? (STDERR)     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)

**Update: Meteor 1.1 still having this issue. **

I have narrowed in on the reason it seems to work, then stop working. If I get my app to run into an error, without catching it then moment will stop working.

To test this I started Meteor, then the Meteor Shell and moment(), it worked. I then got my app to make a call to a non-existent function, which always throws something like the below error. Then I ran moment() from the Meteor Shell again and this time moment() doesn't work. Event if I restart Meteor it still doesn't work. I have restarted the computer and still, it doesn't work.

(STDERR) TypeError: Property 'customer.source.updated' of object #<Object> is not a function
W20150401-13:46:11.812(-5)? (STDERR)     at [object Object].Router.route.where (app/both/router/router.js:254:48)
W20150401-13:46:11.812(-5)? (STDERR)     at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1)
W20150401-13:46:11.812(-5)? (STDERR)     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)
W20150401-13:46:11.812(-5)? (STDERR)     at packages/meteor/dynamics_nodejs.js:121:1
W20150401-13:46:11.812(-5)? (STDERR)     at [object Object].urlencodedParser (/Users/Bechard/.meteor/packages/iron_router/.1.0.7.1oysnq2++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:69:27)
W20150401-13:46:11.812(-5)? (STDERR)     at packages/iron:router/lib/router.js:277:1
W20150401-13:46:11.812(-5)? (STDERR)     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
W20150401-13:46:11.812(-5)? (STDERR)     at [object Object].hookWithOptions (packages/iron:router/lib/router.js:276:1)
W20150401-13:46:11.812(-5)? (STDERR)     at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1)
W20150401-13:46:11.813(-5)? (STDERR)     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)

Upvotes: 3

Views: 1450

Answers (2)

Jesse Rosenberger
Jesse Rosenberger

Reputation: 31

This problem was a bug in the way that Meteor was reloading itself in the shell environment and is fixed in Meteor 1.2. For the relevant bug fix information, you can Git Commit 2e43a9 and ae8395 or Meteor Issue #4010 or #4109.

MomentJS Issue 2285 tracked this issue.

Upvotes: 0

bengreene
bengreene

Reputation: 351

I spent way too long working this exact issue today. I had just updated to Meteor 1.0.4.1 when I got stuck with this issue (although for me, the problem was that moment-range couldn't find moment in order to extend it). Try reverting back to Meteor 1.0.3.2 and see if the problem still persists.

UPDATE:

I just upgraded Meteor to 1.0.5, and the issue may have gone away for me. If you try upgrading your own apps, please post below if it resolves the issue for you as well. Thanks!

Upvotes: 3

Related Questions