angular-seed icon indicating copy to clipboard operation
angular-seed copied to clipboard

Seed-based project fails to load 3rd party modules in dev, but not in prod mode

Open crowder opened this issue 10 years ago • 3 comments

I'm submitting a ... (check one with "x")

[ X ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see use [gitter](https://gitter.im/mgechev/angular2-seed) or [stackoverflow](https://stackoverflow.com/questions/tagged/angular2)```

Current behavior When starting the development environment with "npm start", I am finding all of my 3rd party JS libraries do not load, griping in the browser development console about 404s:

GET http://localhost:5555/node_modules/moment.js 404 (Not Found)

Expected behavior In development mode, third-party libraries should be loadable by XHR without error.

Minimal reproduction of the problem with instructions Not quite sure how to produce a minimal reproduction of this, but maybe something like:

npm install --save moment

Then use it in a component:

`let moment = require('moment');

moment(someDate).format('dddd, MMMM Do YYYY, h:mm:ss A');`

Then attempt to run the app via "npm start". Observe that the app works when run with "npm serve.prod"

What is the motivation / use case for changing the behavior? Development mode is useful.

Please tell us about your environment: Mac OS X, vim, npm, node

**Angular Seed Version:* 2.0.X I believe I am up-to-date with 0c972d671c4337d361f56fa3684dac4601aaedbf, though it's possible I've had conflicts during merges which I have not resolved correctly.

**Node:* node --version = v6.3.1

crowder avatar Oct 19 '16 23:10 crowder

Hey @crowder. I wouldn't call this an issue but more like missing configuration. Take a look at this issue and also the SystemJS configuration. I believe you should add packageConfigPaths to your SYSTEM_BUILDER_CONFIG.

mgechev avatar Oct 19 '16 23:10 mgechev

Thanks for the quick response, @mgechev

For those interested, I resolved the issue based on this recommendation by adding the following to my project.config.ts:

       // {src: `${this.CSS_SRC}/path-to-lib/test-lib.css`, inject: true, vendor: false},
     ];

+    this.SYSTEM_CONFIG_DEV.packageConfigPaths = [
+        `/node_modules/*/package.json`,
+        `/node_modules/**/package.json`,
+        `/node_modules/@angular/*/package.json`
+    ];
+
     /* Add to or override NPM module configurations: */
     // this.mergeObject(this.PLUGIN_CONFIGS['browser-sync'], { ghostMode: false });
   }

I don't fully understand the breakage referenced in the other bug, but it seems there must be a middle ground between these working automagically in dev, and not?

crowder avatar Oct 19 '16 23:10 crowder

We had some issues with different module resolution in systemjs and system builder, probably that's where the problem comes from.

mgechev avatar Oct 19 '16 23:10 mgechev