Anyone else having problems using moment in v1.1?

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

> Package['momentjs:moment']
{ moment: undefined }
> 

yep get that same thing @jamgold

Refrain from using meteor shell. This seems to be a bug with either the package or meteor shell. Everything works for me without the shell.

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.

1 Like

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.

accounts-base@1.2.0
accounts-google@1.0.4
accounts-oauth@1.1.5
accounts-password@1.1.1
accounts-ui@1.1.5
accounts-ui-unstyled@1.1.7
alanning:roles@1.2.13
aldeed:autoform@5.3.2
aldeed:collection2@2.3.3
aldeed:simple-schema@1.3.3
aldeed:tabular@1.2.0
aldeed:template-extension@3.4.3
autopublish@1.0.3
autoupdate@1.2.1
base64@1.0.3
binary-heap@1.0.3
blaze@2.1.2
blaze-tools@1.0.3
boilerplate-generator@1.0.3
callback-hook@1.0.3
check@1.0.5
coffeescript@1.0.6
d3js:d3@3.5.5
ddp@1.1.0
deps@1.0.7
ejson@1.0.6
email@1.0.6
fastclick@1.0.3
frozeman:q@1.0.4
geojson-utils@1.0.3
google@1.1.5
html-tools@1.0.4
htmljs@1.0.4
http@1.1.0
id-map@1.0.3
innovae:bootstrap-stylus@1.0.2
insecure@1.0.3
iron:controller@1.0.8
iron:core@1.0.8
iron:dynamic-template@1.0.8
iron:layout@1.0.8
iron:location@1.0.9
iron:middleware-stack@1.0.9
iron:router@1.0.9
iron:url@1.0.9
jquery@1.11.3_2
json@1.0.3
launch-screen@1.0.2
less@1.0.14
livedata@1.0.13
localstorage@1.0.3
logging@1.0.7
markdown@1.0.4
matb33:collection-hooks@0.7.13
meteor@1.1.6
meteor-platform@1.2.2
meteorhacks:async@1.0.0
meteorhacks:meteorx@1.0.2
meteorhacks:npm@1.4.0
meteorhacks:unblock@1.1.0
minifiers@1.1.5
minimongo@1.0.8
mobile-status-bar@1.0.3
momentjs:moment@2.10.6
mongo@1.1.0
mongo-livedata@1.0.8
mquandalle:jade@0.4.3
mquandalle:jade-compiler@0.4.3
mrt:moment@2.8.1
mrt:q@1.0.1
npm-bcrypt@0.7.8_2
npm-container@1.1.0
oauth@1.1.4
oauth2@1.1.3
observe-sequence@1.0.6
ordered-dict@1.0.3
percolate:google-api@1.0.2
raix:handlebar-helpers@0.2.4
random@1.0.3
reactive-dict@1.1.0
reactive-var@1.0.5
reload@1.1.3
retry@1.0.3
reywood:publish-composite@1.3.6
routepolicy@1.0.5
seanr:date.js@0.0.1
service-configuration@1.0.4
session@1.1.0
sha@1.0.3
spacebars@1.0.6
spacebars-compiler@1.0.6
srp@1.0.3
stylus@1.0.7
templating@1.1.1
tracker@1.0.7
tsega:bootstrap3-datetimepicker@4.14.30_4
tymtu-google-calendar@0.0.1
ui@1.0.6
underscore@1.0.3
url@1.0.4
webapp@1.2.0
webapp-hashing@1.0.3
wizonesolutions:juration@1.0.1