Having trouble importing moment.js into my angular2 application despite following various guides and solutions provided. Even though the package is present in my IDE (Visual Studio) and the moment.d.ts file is easily found, I keep encountering errors when running npm start:
"NetworkError: 404 Not Found - http://localhost:3000/node_modules/moment/" /node_m...moment/ Error: patchProperty/desc.set/wrapFn@http://localhost:3000/node_modules/zone.js/dist/zone.js:769:27 Zonehttp://localhost:3000/node_modules/zone.js/dist/zone.js:356:24 Zonehttp://localhost:3000/node_modules/zone.js/dist/zone.js:256:29 ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:423:29
Error loading http://localhost:3000/node_modules/moment as "moment" from 'my file'
Various attempts have been made to import moment.js with no success, including:
import * as moment from 'moment'
and
import * as moment from 'moment/moment.d'
However, these methods still result in errors. My SystemJs map property includes:
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'services': 'app/service',
'moment': 'node_modules/moment',//moment.js
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs'
};
Attempts to install typings also faced issues:
Typings for "moment" already exist in "node_modules/moment/moment.d.ts". You should let TypeScript resolve the packaged typings and uninstall the copy installed by Typings
After troubleshooting this, I encountered the error:
typings ERR! message Unable to find "moment" ("npm") in the registry.
Is there a solution to overcome this dilemma?