NPM 7/8 is not installing peer dependencies
Asked Answered
npm
N

2

7

I'm trying to build a repository/package for my personal ESLint config files. I have all of my configuration files built the way I would like, and now I am trying to install this package to test it.

In this scenario, I have two packages:

  • @me/eslint-config is the package containing my ESLint config files.
  • test-package is the package on/in which I am trying to install @me/eslint-config.

When I try to install the @me/eslint-config package, peer dependencies are not installed, nor are they even mentioned during the installation.

Both packages currently only reside locally on my machine, side-by-side, in the same directory:

<parent_dir>:
  - eslint-config
    - package.json
    - ...
  - test-package
    - package.json
    - ...

The package.json file for @me/eslint-config looks as follows:

{
    ...
    "dependencies": {
        "@typescript-eslint/parser": "5.29.0"
    },
    "peerDependencies": {
        "eslint": "8.18.0",
        "eslint-plugin-import": "2.26.0",
        "eslint-plugin-jsdoc": "39.3.3",
        "eslint-plugin-prefer-arrow": "1.2.3",
        "@typescript-eslint/eslint-plugin": "5.29.0"
    }
    ...
}

I am installing this package in test-package as follows:

$> cd /path/to/test-package
$> npm i ../eslint-config --save-dev

NPM properly installs all other dependencies, including the @me/eslint-config package itself, but does not install the peerDependencies of @me/eslint-config.

This is using NPM v8.1.0.

This article seems to suggest that NPM >7 installs peer dependencies automatically. This is obviously not working for me.

Things I have already tried that have not fixed the problem:

  • Deleting node_modules/ and package-lock.json from test-package and reinstalling everything.
  • Pinning all peerDependencies versions in @me/eslint-config.
  • Adding all peerDependencies in @me/eslint-config as both dependencies and peerDependencies in @me/eslint-config.

tl;dr NPM isn't installing peerDependencies

Nigrosine answered 24/6, 2022 at 20:55 Comment(2)
Any luck of finding out why? I'm having the same issue right now.Epimorphosis
Do you have a .npmrc file? Show the config.Sherleysherline
S
1

I had the same error on former version of npm and as you mention, npm ^8 now install peer dependencies.

But here could be ways of fining your problem

1 : estlint is a devDependencies (A guess)

eslint should be devDependencies and not a peerDependencies.
Maybe npm doesn't accept you to install it then.

I search a bit but couldn't find any real thread discussing about this

That said, I wouldn't install it as dependencies since it will be pushed to your production build, what, I think, you do not want.

2 : Being up to date

Try it with the latest version of npm

  1. download the latest version of npm : npm install -g npm@latest
  2. Delet node_modules/ and package-lock.json from test-package and reinstall everything. as you did already

2 : allowJs

If eslint is an js package & you see it being installed in the node_modules folder.

  1. Inside the tsconfig.json file, under the compilerOptions add allowJs: true and set strict: false
  "compilerOptions": {
    "allowJs": true,
    "strict": false,
  1. Close all your instance of vs-code
  2. Restart & retry (No need to remove the package-lock or so)
Scholasticism answered 13/7, 2022 at 4:55 Comment(0)
A
0

What it worked for me is what is described in point 2. from Raphaël's answer:

$ npm cache clean --force
$ rm -rf node_modules package-lock.json
$ npm install

Unfortunately, I still don't understand why these steps solves the issue.

Athos answered 28/8 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.