I'm working on an Angular library in a monorepo comprised of multiple projects which we publish separately and use internally across multiple apps. Our tooling has been fairly archaic until now. I'm trying to update us to use npm workspaces to get more efficient dependency & package management.
All the examples I see online show the each of the libraries declaring all their dependencies as dependencies in package.json, not peerDependencies. NPM workspaces does its thing organizing the library packages, and I see my dependencies collated in the central node_modules directory.
Unfortunately, when I try to build my libraries I get errors like:
$ ng build library-a
...
Building Angular Package
------------------------------------------------------------------------------
Building entry point 'library-a'
------------------------------------------------------------------------------
✔ Compiling with Angular sources in Ivy partial compilation mode.
✔ Writing FESM bundles
✔ Copying assets
⚠ Distributing npm packages with 'dependencies' is not recommended. Please consider adding @angular/core to 'peerDependencies' or remove it from 'dependencies'.
✖ Writing package manifest
Dependency @angular/core must be explicitly allowed using the "allowedNonPeerDependencies" option.
I understand that ng-packagr is opinionated about peerDependencies, but I don't understand how all those examples I've seen actually build. In ng-package.json I can either:
- Specify
"allowedNonPeerDependencies": ["*"]to make it shut up about everything; or - Duplicate all of my
dependenciesfrom package.json, which is an error-prone copy-pasta exercise across all of our libraries, which sounds painful and redundant.
Either way, this smells fishy to me. If either solution were necessary it seems like it would be on the Page 1 of the documentation. I haven't seen anything about how to treat dependencies vs peerDependencies for npm workspaces anywhere.
What am I missing? What are other people doing? Thank you!