I am trying to create a library as npm package using ng generate library ts-utils
command
This library use of a dependency called memoizee, where we include the library and its respective @types in the peerDependencies
section of the library.
NOTE: nowhere else in my package do I reference these dependencies only in package.json
{
"name": "@heanfig/ts-utils",
"version": "1.0.1",
"description": "Plugin for TypeScript to support custom decorators and functions",
"peerDependencies": {
"@angular/common": "^13.2.0",
"@angular/core": "^13.2.0",
"@types/memoizee": "^0.4.7",
"memoizee": "^0.4.15"
},
"dependencies": {
"tslib": "^2.3.0"
},
...
}
When I try to generate the library and publish it to npmjs it does not generate any problems,
When I try to use it by installing it in the project that needs it, it generates a warning similar to this:
Warning: /Users/hermanfigueroaidarraga/Desktop/@hf/ts-utils-demo/dist/ts-utils/fesm2015/heanfig-ts-utils.mjs depends on 'memoizee'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Additionally it tells me that memoizee
is undefined
, and when I go to check in the project where I installed the dependency, inside the node_modules
folder there is both memoizee and its types
Apparently there is a module, commonJS or umd types error but the exact cause of this error cannot be determined because my package does not find the dependency knowing that it is correctly installed in the node_modules directory with its respective types
Thanks for the attention
memoizee
and its types should go into dependencies
section for your library.
peer dependancies are intended for extension by plugin (e.g. the @angular/...
dependencies, as they are target for extension) see the documentation here https://nodejs.org/es/blog/npm/peer-dependencies/