I want to dynamically import the moment.js package. I’m hoping someone will be kind enough to help me.
I just upgraded to Meteor 1.5.
I ran the following command:
$ meteor remove momentjs:moment && npm install --save moment
I have a Blaze helper function that uses moment to format dates:
FormatDate () {
const moment = import('moment');
if (this.DateUpdated) {
return moment(new Date(this.DateUpdated)).startOf('hh').fromNow();
} else {
return 'no activity';
}
}
I run the app and from the console, this is what the function looks like:
FormatDate: function () { // 119
var moment = module.dynamicImport('moment'); // 120
//
if (this.DateUpdated) { // 122
return moment(new Date(this.DateUpdated)).startOf('hh').fromNow(); // 123
} else { // 124
return 'no activity'; // 125
} // 126
}
And I get the following error:
Exception in template helper: TypeError: moment is not a function
My package.json:
"dependencies": {
"babel-runtime": "^6.23.0",
"bcrypt": "^1.0.2",
"moment": "^2.18.1",
},