Ember-cli: Problem with import momentjs

Created on 29 Feb 2016  Â·  5Comments  Â·  Source: ember-cli/ember-cli

First, generate the shim:

ember generate vendor-shim moment

Next, provide the vendor asset path:

app.import('vendor/shims/moment.js');
Finally, use the package by adding the appropriate import statement:

import moment from 'moment';

// ...
var day = moment('Dec 25, 1995');

But throw error when run moment : `Uncaught (in promise) TypeError: (0 , _moment.default) is not a function(…)``

I using ember-cli 2.3.0

Most helpful comment

assuming moment is amd:

app.import('bower_components/moment/moment.js', {
  amdModule: 'moment'
})

All 5 comments

Just to confirm, are you importing moment before your shim?

The following seems to work

app.import('bower_components/moment/moment.js');
app.import('vendor/shims/moment.js');

The shim is a default vendor-shim blueprint generated file and moment is from bower. If you're dead keen on using npm I think you may be better off using ember-browserify.

Solved my problem @lpaluszk thanks :dancer:

I opened an RFC issue to discuss a more elegant solution for this: https://github.com/ember-cli/rfcs/issues/84

assuming moment is amd:

app.import('bower_components/moment/moment.js', {
  amdModule: 'moment'
})
Was this page helpful?
0 / 5 - 0 ratings