javascript - SystemJS - moment is not a function -


i'm using jspm, angularjs, typescript, systemjs , es6 , project running pretty well... unless try use momentjs.

this error get:

typeerror: moment not function

this part of code:

import * moment 'moment'; 

more:

var momentinstance = moment(value); 

if debug it, moment object not function:

enter image description here

this moment.js jspm package looks like:

module.exports = require("npm:moment@2.11.0/moment.js"); 

i've read lot , couldn't find way solve this... ideas?

some things i've read/tried:

how use momentjs in typescript systemjs?

https://github.com/angular-ui/ui-calendar/issues/154

https://github.com/jkuri/ng2-datepicker/issues/5

typescript module systems on momentjs behaving strangely

https://github.com/dbushell/pikaday/issues/153

thanks!

simply remove grouping (* as) import statement:

import moment 'moment'; 

without digging in source code, looks moment exports function, has kinds of methods , other properties attached it.

by using * as, you're grabbing properties , attaching them new object, destroying original function. instead, want chief export (export default in es6, module.exports object in node.js).

alternatively, do

import moment, * moments 'moment'; 

to moment function as moment, , other properties on object called moments. makes little less sense when converting es5 exports es6 style, because moment retain same properties.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -