1

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

enter image description here

enter image description here

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

2
  • Not really a solution for you, but in our project we publish a package to a private npm repo and had the same error... I ended up just manually putting the peerDependency as a dependency in the consuming application and that resolves this..... Something about certain version of npm not installing peerDependencies by default. Commented Mar 9, 2022 at 1:32
  • 1
    @Zze FYI, Node version 16+ (And its corresponding NPM versions) install peerDependencies by default. But in versions before that, it expects you to install peerDependencies by hand. Commented Sep 27, 2023 at 12:42

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.