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
./
../
.editorconfig
.gitignore
angular.json
dist/
node_modules/
package.json
package-lock.json
projects/
projects/my-lib/
projects/my-lib-runner/
README.md
tsconfig.base.json
tsconfig.json
tslint.json
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?