-1

With NPM 7, peer dependencies are now installed automatically. How can I disabled this behavior?

Context:

I have an Angular NX Monorepo and I want to install only one copy of Angular at the root, also I want to install library inside "my-app". That library has Angular as a peer dependency. With NPM 6 Angular was only installed at the root node_modules, because peer dependencies were not installed automatically. But with NPM 7, Angular is also installed inside "my-app"'s node_modules

Project structure:

apps:
  my-app:
    node_modules: 
      @angular
    package.json
node_modules:
  @angular
package.json

As you can see in the structure above, two copies of Angular are being installed. With NPM 6 I would have only one copy, at the root level.

coltrane
  • 39
  • 5

1 Answers1

0

After doing my research, I found out that such dependencies are recommended to be installed in the root of the project.

But if you really need to disable automatic peer dependency installation, you can create a .npmrc file in the package where you don't want to install peer dependencies and specify

omit = peer

This will tell NPM that you don't want to automatically install peer dependencies.

Source: https://docs.npmjs.com/cli/v8/using-npm/config#omit

coltrane
  • 39
  • 5