I\'m trying to follow the official AoT guide for Angular 2, and I\'m using Moment.js in my application. Moment.js is on my packages.json file, and I\'m using versio
Had same problem with momentJs (2.24) usage in my Angular 5 (5.2.9) project (upgraded from Ng2) with Gulp and Rollup (0.58.0) for prod build.
As guys mentioned earlier here import * as moment from 'moment';
works only for deving (via SystemJS) with referring momentJs in packages list:
{
name: 'moment',
path: 'node_modules/moment/min/moment.min.js'
}
Other case is Rollup usage (Production build) - momentJs have its code as ES6 module (in moment/src), but it exports in different way (then usual export).
That's why import moment from 'moment';
works with Rollup's
include: [
'node_modules/rxjs/**',
]
and ES6 modules import.
Yes, to use ES6 wrapper (such as moment-es6
or so) is simple solution. But it always requires momentJs.
Same time there is one more simple solution for this issue - replace your import row from Dev to Prod.
For example, Gulp can use gulp-replace
at some step:
return gulp.src([
...
])
.pipe(replace('import * as moment from \'moment\';', 'import moment from \'moment\';'))
...;