I am in the process of migrating some components which are being used in several other projects into their own component-library to avoid code duplication, among all the other advantages. It seems though I am having trouble understanding the concept of dependencies vs. peerDependencies and where to put the dependencies (library workspace package.json or library package.json?).
I added the @angular-dependencies as suggested in the official documentation to the peerDependencies of the library-package.json. But now I am getting errors building the consumer-project which uses the library:
Argument of type 'import("C:/GITROOT/cspp/my-consumer/node_modules/@angular/platform-browser/index").Title' is not assignable to parameter of type 'import("C:/GITROOT/cspp
/my-library/node_modules/@angular/platform-browser/index").Title'.
Obviously there is a version conflict of the @angular/platform-browser package, even though I added the same specific versions to the consumer-package.json AND the library-package.json:
"@angular/platform-browser": "14.2.10",
Looking inside the library-projects node_modules-folder I noticed that it installed version 14.3.0 even though it says 14.2.10 in the package.json. How can that be? Similar issues occur regarding the rxjs-dependency. Im very confused about where to put the library dependencies so those issues dont happen. I can prevent those issues from happening by adding
"paths": {
"@angular/*": [
"node_modules/@angular/*"
],
"rxjs": [
"node_modules/rxjs"
],
"rxjs/*": [
"node_modules/rxjs/*"
],
"my-library": [
"../../../my-library/dist/my-awesome-lib"
],
},
but this feels like a hack...