Search code examples
javascriptnode.jsmeteormomentjseonasdan-datetimepicker

““Meteor - tsega/meteor-bootstrap3-datetimepicker TypeError: locale() locale it is not loaded from moment locales!“


The console log retun this error

tsega/meteor-bootstrap3-datetimepicker TypeError: locale() locale it is
not loaded from moment locales!

I'm using meteor with this version Meteor 1.4.1.1 with the tsega:bootstrap3-datetimepicker v4.17.37_1 and momentjs:moment v2.14.4 packages.

As per the example I have the following code to initialize the date time picker:

Template.nuovoCantiere.onRendered( () => {
  $( '.datetimepicker' ).datetimepicker({
    timeZone: 'Europe/Rome',
    format: 'D/MM/YYYY',
    locale: 'it'
  });
});

I read that the moment.js packages has been flagged as not working:

"Flagged Package This package has been flagged as not working by the community. Use at your own risk."

So I tried to use the NPM version of moment.js:

var moment = require('moment');
require('moment/locale/it');

Template.nuovoCantiere.onRendered( () => {
  $( '.datetimepicker' ).datetimepicker({
      timeZone: 'Europe/Rome',
      format: 'D/MM/YYYY',
      locale: 'it'
  });
});

but the console returns the same error

TypeError: locale() locale it is not loaded from moment locales!


Solution

  • I've passed by the very same situation. And it has honestly a very simple solution concerning Meteor development:

    1. $ meteor add rzymek:moment
    2. $ meteor add rzymek:moment-locale-it

    Restart your app and that's it. There's no need to reference a node-module (i.e var moment = require('moment');) and stuff.