mgechev / angular-seed

🌱 [Deprecated] Extensible, reliable, modular, PWA ready starter project for Angular (2 and beyond) with statically typed build and AoT compilation
https://mgechev.github.io/angular-seed
MIT License
4.57k stars 1.45k forks source link

date-formatter.ts not able to find moment.ts #442

Closed harikrishna266 closed 8 years ago

harikrishna266 commented 8 years ago

when i add ng2-bootstrap in my project, I get an error that moment.js is not found.

mgechev commented 8 years ago

Have you tried to add moment as dependency? The seed doesn't contain moment.js so you need to install it.

harikrishna266 commented 8 years ago

I think i have installed momentjs. This is the dependencies in package.json

"dependencies": {
    "angular2": "2.0.0-beta.2",
    "bootstrap": "^3.3.5",
    "es6-module-loader": "^0.17.8",
    "es6-shim": "^0.33.3",
    "moment": "^2.11.2",
    "ng2-bootstrap": "^1.0.3",
    "ng2-file-upload": "^1.0.0-beta.1",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "systemjs": "0.19.9",
    "underscore": "^1.8.3",
    "zone.js": "0.5.10"
  }

I have edited the file named date-formatter.js from var moment = require('moment'); to var moment = require('../../../moment/moment'); and then it seems to work. The issue is that everybody in the team has to edit the file node_module/ng2-bootstrap/components/datepicker/date-formatter.js

i think this is more of ng2-bootstrap based issue. You may close this issue. Thanks

ceelian commented 8 years ago

A quick workaround:

Add the following line anywhere in the constructor of project.config.ts:

(<any>this.SYSTEM_BUILDER_CONFIG.paths)['moment'] ='node_modules/moment/moment.js';

quiringk commented 8 years ago

I had this issue today. I tried many different changes to my systemjs.config.js file and kept getting

localhost/:20 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/moment(…)

@harikrishna266's answer was the only one that worked after hours of trying to figure out what happened. The weird thing was I got ng2-bootstrap to work a couple weeks ago before I reconstructed my project to look more like the new quickstart on angular 2 with the systemjs.config.js file, etc. (I literally redownloaded quickstart and updated with all my files to replicate) Why did I have to make this change for ng2-bootstrap to work?

Also, now that it is working, I am getting this message even though it is working: Uncaught ReferenceError: System is not defined

Here is my relevant systemjs.config.js:

// map tells the System loader where to look for things var map = { 'app': 'app', // 'dist', 'rxjs': 'node_modules/rxjs', 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', '@angular': 'node_modules/@angular', 'moment': 'node_modules/moment', 'ng2-bootstrap': 'node_modules/ng2-bootstrap' };

// packages tells the System loader how to load when no filename and/or no extension var packages = { 'app': { main: 'main.js', defaultExtension: 'js' }, 'rxjs': { defaultExtension: 'js' }, 'angular2-in-memory-web-api': { defaultExtension: 'js' }, 'moment': { defaultExtension: 'js' }, 'ng2-bootstrap': { defaultExtension: 'js' } };