Canot find module used in custom angular library

  angular, angular-library, typescript

I’m building a custom library with angular so that I can create components in this library that will be re-used through many future applications. I began with creating a few components and a couple services. One of the services requires a dependency of oidc-client. So inside my library I ran an npm install oidc-client. The dependency was added under my libraries package.json dependencies section. I began getting errors, read some of the documentation and found that this should actually be under the peerDependencies section, and not the dependencies section of my libraries package.json.

My folder/file layout is as so


What I do to test run my library is do a

ng build my-lib --watch

in one terminal, and then in another I run

ng serve my-lib-runner

When I run the -runner is when I get this error

ERROR in dist/my-lib/lib/core/services/auth.service.d.ts:2:22 - error TS2307: Cannot find module 'oidc-client' orr its corresponding type declarations.

2 import { User } from 'oidc-client';

And then here’s the package.json for projects/my-lib/

  "name": "my-lib",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^10.0.14",
    "@angular/core": "^10.0.14",
    "@angular/material": "^10.2.2",
    "@angular/flex-layout": "^10.0.0-beta.32",
    "oidc-client": "^1.10.1",
    "tslib": "^2.0.0"

I thought as a peer dependency, the project that references the library would either automatically download the necessary package on npm install or it would be included in the npm install my-lib.

What am I doing wrong?

Source: Angular Questions

One Reply to “Canot find module used in custom angular library”

  • adding under peerDependencies leaves it to the developer using your custom library to freely choose if they want to install the dependencies needed to support your custom library (e.g. maybe they already have it in their project so no need to install it). It’s best to use your documentation to list out what dependencies are needed to make your custom library work. If you put it under “dependencies”, it means when you npm install <your custom library> it will automatically install those supporting libraries; forcing the developer to take on your those dependencies. The problem lies when you force installation of a dependencies can cause more problems due to duplicate dependencies of different version.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.