Skip to content

[BUG] Locally-installed package should satisfy peer dependency #2199

Description

@btmills

Current Behavior:

npm install in the eslint/eslint repository fails when it tries to resolve a transitive peer dependency on eslint@>=5.0.0 and finds eslint@undefined.

We want to dogfood eslint in development, so we specify it in our devDependencies as "eslint": "file:.". We also depend on a third-party plugin, eslint-plugin-eslint-plugin, which lists eslint@>=5.0.0 in its peerDependencies.

Running npm install reports ERESOLVE unable to resolve dependency tree having found eslint@undefined, which fails the eslint@>=5.0.0 requirement. (Full output and eresolve-report.txt included in the repro steps.)

eslint@7.13.0`s package.json snippet
```json
{
	"name": "eslint",
	"version": "7.13.0",
	"devDependencies": {
		"eslint": "file:.",
		"eslint-plugin-eslint-plugin": "^2.2.1"
	}
}
```
eslint-plugin-eslint-plugin@2.3.0`s package.json snippet
```json
{
	"name": "eslint-plugin-eslint-plugin",
	"version": "2.3.0",
	"peerDependencies": {
		"eslint": ">=5.0.0"
	}
}
```

Expected Behavior:

Ideally, instead of finding eslint@undefined, eslint-plugin-eslint-plugin's eslint@>=5.0.0 peer dependency is satisifed by eslint@7.13.0, which is already "installed" from file:.. Install continues on as normal. (It won't succeed yet because I'm still working on upgrading another dependency to a newer version that lists eslint@^7.0.0 as a compatible peer dependency, but eslint-plugin-eslint-plugin at least should be happy.)

If that's not an option, our current solution so that we can test Node 15 in CI is to install with the --legacy-peer-deps flag. I also found that replacing file: dependencies with workspaces installs successfuly. At some point in the future when we can require at least npm v7, we could switch from --legacy-peer-deps to workspaces.

Steps To Reproduce:

$ node --version
v15.2.1
$ npm --version
7.0.10
$ git clone https://github.com/eslint/eslint.git
$ cd eslint
# Latest version as of writing in case a future commit no longer repros
$ git checkout v7.13.0
$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: eslint@7.13.0
npm ERR! Found: eslint@undefined
npm ERR! node_modules/eslint
npm ERR!   dev eslint@"file:." from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@">=5.0.0" from eslint-plugin-eslint-plugin@2.3.0
npm ERR! node_modules/eslint-plugin-eslint-plugin
npm ERR!   dev eslint-plugin-eslint-plugin@"^2.2.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See ~/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2020-11-19T05_00_04_565Z-debug.log
~/.npm/eresolve-report.txt
# npm resolution error report

2020-11-19T05:00:04.563Z

While resolving: eslint@7.13.0
Found: eslint@undefined
node_modules/eslint
  dev eslint@"file:." from the root project

Could not resolve dependency:
peer eslint@">=5.0.0" from eslint-plugin-eslint-plugin@2.3.0
node_modules/eslint-plugin-eslint-plugin
  dev eslint-plugin-eslint-plugin@"^2.2.1" from the root project

Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

Raw JSON explanation object:

{
  "code": "ERESOLVE",
  "current": {
    "name": "eslint",
    "errors": [
      {}
    ],
    "package": {},
    "whileInstalling": {
      "name": "eslint",
      "version": "7.13.0",
      "path": "~/code/eslint/eslint"
    },
    "location": "node_modules/eslint",
    "dependents": [
      {
        "type": "dev",
        "name": "eslint",
        "spec": "file:.",
        "from": {
          "location": "~/code/eslint/eslint"
        }
      }
    ]
  },
  "edge": {
    "type": "peer",
    "name": "eslint",
    "spec": ">=5.0.0",
    "error": "INVALID",
    "from": {
      "name": "eslint-plugin-eslint-plugin",
      "version": "2.3.0",
      "whileInstalling": {
        "name": "eslint",
        "version": "7.13.0",
        "path": "~/code/eslint/eslint"
      },
      "location": "node_modules/eslint-plugin-eslint-plugin",
      "dependents": [
        {
          "type": "dev",
          "name": "eslint-plugin-eslint-plugin",
          "spec": "^2.2.1",
          "from": {
            "location": "~/code/eslint/eslint"
          }
        }
      ]
    }
  },
  "peerConflict": null,
  "strictPeerDeps": false,
  "force": false
}

Environment:

  • OS: macOS 10.15.7
  • Node: 15.2.1
  • npm: 7.0.10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingPriority 0will get attention right awayRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions