meteor - Momentjs 与 Meteor 似乎无法在服务器端工作

标签 meteor momentjs

我在我的 meteor 项目中使用了 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 仍然存在此问题。 **

我已经缩小了它似乎有效的原因,然后停止工作。如果我的应用程序遇到错误而没有捕获它,那么 moment 将停止工作。

为了测试这一点,我启动了 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)

最佳答案

今天我花了太长时间来解决这个问题。当我遇到这个问题时,我刚刚更新到 Meteor 1.0.4.1(尽管对我来说,问题是 moment-range 找不到 moment 来扩展它)。尝试恢复到 Meteor 1.0.3.2,看看问题是否仍然存在。

更新:

我刚刚将 Meteor 升级到 1.0.5,这个问题可能已经消失了。如果您尝试升级自己的应用程序,如果它也为您解决了问题,请在下面发帖。谢谢!

关于meteor - Momentjs 与 Meteor 似乎无法在服务器端工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29135488/

相关文章:

meteor - 从服务器获取结果后在 Meteor 中调用客户端 js 函数

javascript - 在网站中加载外国内容比 document.write() 更好的做法?

mysql - 现有 mysql 数据库中数据的 meteor 报告。如何?

javascript - Moment.js 的简单函数给出了意想不到的(?)结果

javascript - 如何获得两个时刻之间的日历周差?

mongodb - Mongoose 中的时刻 js 没有更新

javascript - Meteor 出现意外的 mongo 退出代码 100

mongodb - 开发期间的 meteor 自定义mongodb

javascript - 查找一系列 JavaScript 日期中最早的日期

momentjs - 如何使用 HH :mm format? 在 moment js 中添加分钟