1

I made a component library using the Angular CLI and I have have a separate test application that imports this library.

The component library builds nicely, but I am having trouble running "ng serve" in the test application because one of the components in the library uses an npm package I specifically installed in the library: 'jwt-decode".

For instance one component in the library has the line:

import * as jwt_ from 'jwt-decode';

And the library's package.json has the lines

"dependencies": {
    "@types/jwt-decode": "^2.2.1",
    "jwt-decode": "^2.2.0"
 }

While the component library builds correctly, when I ng-serve the application that imports this library, I get the error:

Module not found: Error: Can't resolve 'jwt-decode' in '.../dist/myLibrary/fesm2015'.

Basically, how do I export a package(that I npm installed in the library), with the component library itself. Do I need to add anything to the library's public-api.ts file?

ACarr
  • 89
  • 6
  • You have to install the dependencies into the application that uses the library. So you have to run `npm install jwt-decode` in the app. – Reactgular Aug 07 '19 at 19:24
  • Theres no way around this? I'm trying to abstract this, since only the component needs it from the component library and not the separate application. – ACarr Aug 07 '19 at 19:28
  • It has nothing to do with Angular. This is how npm works. You have a peer dependency and the app might be using the same library but a slightly different version. So the app decides which library gets installed and what version. – Reactgular Aug 07 '19 at 19:44

0 Answers0