filipesilva / angular-quickstart-lib

MIT License
305 stars 75 forks source link

Demo app fails when using util package in a library component #52

Open Bradleycorn opened 7 years ago

Bradleycorn commented 7 years ago

Steps to reproduce:

  1. clone the repo, and npm install
  2. npm install --save-dev util
  3. update the /src/lib/src/component/lib.component.ts file with:
    import {isNullOrUndefined} from 'util';

    and give the component a constructor as follows:

    constructor() {
    let bool = (isNullOrUndefined(name));
    }
    1. run the demo app: npm start

The app doesn't load, and the console gives errors about not being able to find util.

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3002/util
    Error: XHR error (404 Not Found) loading http://localhost:3002/util
        at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:3002/node_modules/zone.js/dist/zone.js:1075:39)
        at ZoneDelegate.invokeTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:424:31)
        at Zone.runTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:191:47)
        at ZoneTask.invokeTask [as invoke] (http://localhost:3002/node_modules/zone.js/dist/zone.js:498:34)
        at invokeTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:1370:14)
        at XMLHttpRequest.globalZoneAwareCallback (http://localhost:3002/node_modules/zone.js/dist/zone.js:1388:17)
    Error loading http://localhost:3002/util as "util" from http://localhost:3002/quickstart-lib/src/component/lib.component.js
        at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:3002/node_modules/zone.js/dist/zone.js:1075:39)
        at ZoneDelegate.invokeTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:424:31)
        at Zone.runTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:191:47)
        at ZoneTask.invokeTask [as invoke] (http://localhost:3002/node_modules/zone.js/dist/zone.js:498:34)
        at invokeTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:1370:14)
        at XMLHttpRequest.globalZoneAwareCallback (http://localhost:3002/node_modules/zone.js/dist/zone.js:1388:17)
    Error loading http://localhost:3002/util as "util" from http://localhost:3002/quickstart-lib/src/component/lib.component.js

How can we use 'util' with the demo project?

ttma1046 commented 7 years ago

You need to add the entry of 'util' in the systemjs.config.js of the demo app.

Bradleycorn commented 7 years ago

Like so?

    map: {
      'util': 'node_modules/util',

       // ... additional maps ...
     }

I tried that ... it didn't work. also tried setting the path to node_modules/util/util.js, still didn't work. Also tried adding an entry to packages for util, still didn't work.

ttma1046 commented 7 years ago

Hi,

Could you post the error after you adding 'util': 'node_modules/util/util.js' entry into the 'map' section of the systemjs.config.js inside of the demo app?

Btw since 'util' is something your lib component directly depended on, it should be in the 'dependencies' of the package.json not 'devdependencies'.

I guess 'npm install util --save' instead of 'npm install util --save-dev'.

mlwilkerson commented 6 years ago

@Bradleycorn I faced the same problem and what worked for me was to add the dependency under the "paths" key in systemjs.config.js, rather than the "map" key:

    paths: {
      // ...
      'util': 'node_modules/util',
      // ... others
    },