【发布时间】:2015-03-19 01:03:05
【问题描述】:
我在我的流星项目中使用了 momentjs:moment 包。客户端moment(new Date()) 调用效果很好。如果我在服务器端进行相同的调用,或者如果我在console.log(moment(new Date())); 中包含相同的调用,我会在这个问题的底部得到错误。
如果我运行meteor shell,然后运行moment(new Date());,我也会得到一个错误(moment is not defined)。但是,如果从 shell 中将其包装在 console.log(moment(new Date())); 中,它可以正常工作并打印到控制台。
知道我在这里忘记了什么或没有做什么吗?
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)
**更新:Meteor 1.1 仍然存在这个问题。 **
我已经缩小了它似乎工作的原因,然后停止工作。如果我让我的应用程序遇到错误,而没有发现它,那么时刻将停止工作。
为了测试这一点,我启动了 Meteor,然后是 Meteor Shell 和 moment(),它起作用了。然后我让我的应用程序调用一个不存在的函数,该函数总是抛出类似下面的错误。然后我再次从 Meteor Shell 运行 moment() ,这次 moment() 不起作用。如果我重新启动 Meteor,它仍然无法正常工作。我已经重新启动了计算机,但它仍然无法正常工作。
(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)
【问题讨论】:
-
我在使用
momentjs:moment和1.0.4.1 时没有遇到这个问题,但我有时会成功更改packages文件中的包顺序。每个包都应该声明它的依赖关系,但永远不要少......