I was trying to use moment in my meteor application.
Meteor.methods({
createPageFromTemplates: function(pageTemplates) {
var templateIds = _.uniq(_.flatten(_.pluck(pageTemplates, 'templateIds')));
var defaultDuration = _.max(_.pluck(pageTemplates, 'duration'));
var endDate = moment().add(defaultDuration, 'weeks');
// ...
return {
title: "New page template",
startDate: new Date(),
endDate: endDate.toDate(),
templateIds: templateIds
}
}
});
However, I keep getting the following traceback on using moment()
> var t = PlanTemplates.find().fetch()
> Meteor.call('createPlanFromTemplates', t);
TypeError: Property 'moment' of object #<Object> is not a function
at [object Object].Meteor.methods.createPlanFromTemplates (app/both/plans/methods.js:21:19)
at [object Object].methodMap.(anonymous function) (packages/meteorhacks:kadira/lib/hijack/wrap_session.js:160:1)
at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
at packages/ddp/livedata_server.js:1530:1
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at [object Object]._.extend.apply (packages/ddp/livedata_server.js:1529:1)
at [object Object]._.extend.call (packages/ddp/livedata_server.js:1472:1)
at repl:1:8
at [path]/server/shell-server.js:243:23
Anyone else having this problem? Know of any solutions?
Which moment package are you using? When I use momentjs:moment and connect to the Meteor shell and look at the exported object, it is undefined, which seems to correspond to this github issue
It’s a problem with meteor shell. It’s a side-effect of a changed introduced in v1.0.4. I haven’t submitted a bug report to MDG yet because I haven’t been able to create a reliable reproduction recipe. If you have one, feel free to open an issue.
I think I have one. I’ll see if they have a bug open yet. I’m not convinced that there is no issue with Moment, in fact I can even recreate the problem in my own app. See here for more.
I’ve been able to reproduce the issue consistently with the Todos example app. I’ve detailed the steps on this GitHub issue, but I’ll post the steps below as well:
I’ve found a way to reproduce the issue with the Todos example app. If meteor shell starts before meteor, once it connects, moment will be undefined.
meteor create --example todos
cd todos
meteor add momentjs:moment
meteor shell
The server will be unavailable, so the shell tool will wait for a connection. In another terminal session:
meteor
Now, if you enter moment() in the shell, you’ll get an error.
I’m also reporting this problem. I can execute a moment() on the server from the shell, but only until I make a change, triggering a rebuild. After that, I get an error
adam@babbage ~/Programming/tymtu meteor shell
Welcome to the server-side interactive shell!
Tab completion is enabled for global variables.
Type .reload to restart the server and the shell.
Type .exit to disconnect from the server and leave the shell.
Type .help for additional help.
> loadSomeTestData("fu5u8tCkuWWx8QQo9")
[ '6S7hg96asYpRsaq3n',
'6pLdCArkt5cWpWEPx',
'8cJuvYMQbawQHpniz',
'hvBmtnQw74FHrzzdM',
'uApNs8wGCJW6EZcrw',
'jRoABwWvwqAYLkdbf',
'c73TWAwtXdouaFww5',
'ycdFkYMXYb5RYF8GP',
'GZgYGpnxYfqLGooQv',
'eaT9EF2u5zLxfMhm8' ]
> Server unavailable (waiting to reconnect) // here is where the app rebuilt
Welcome to the server-side interactive shell!
Tab completion is enabled for global variables.
Type .reload to restart the server and the shell.
Type .exit to disconnect from the server and leave the shell.
Type .help for additional help.
> loadSomeTestData("fu5u8tCkuWWx8QQo9")
TypeError: Property 'moment' of object #<Object> is not a function
at loadSomeTestData (server/test.coffee:4:8)
at repl:1:2
at /Users/adam/Programming/tymtu/.meteor/local/build/programs/server/shell-server.js:243:23
At that point, I have to completely shut down and restart the app. Calling .reload from the shell does nothing.