Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Hoisting dependencies with peerDependencies can lead to unmet peer dependencies #19877

Open
1 of 4 tasks
filipesilva opened this issue Feb 21, 2018 · 7 comments
Open
1 of 4 tasks

Comments

@filipesilva
Copy link

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

There seems to be a problem with how npm@5.6.0 hoists dependencies that have peer dependencies.

I have prepare a repro at https://github.com/filipesilva/ajv-peerdep-issue. Running npm install in this repository will show the following warning:

npm WARN ajv-keywords@3.1.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

The following dependencies are relevant:

  • this repro itself depends on two packages: ajv@5.5.2 and webpack@3.11.0.
  • webpack@3.11.0 depends on ajv@^6.1.0 and ajv-keywords@^3.1.0.
  • ajv-keywords@3.1.0 has a peer dependency on ajv@^6.0.0

When npm resolves these dependencies they end up looking like this:

ajv-peerdep-issue@1.0.0 D:\sandbox\ajv-peerdep-issue
`-- ajv@5.5.2
`-- ajv-keywords@3.1.0
`-- webpack@3.11.0
  `-- ajv@6.1.0

This is a problem because the hoisted ajv-keywords@3.1.0 will not have its peer dependency on ajv@^6.0.0 met.

How can the CLI team reproduce the problem?

git clone https://github.com/filipesilva/ajv-peerdep-issue
cd ajv-peerdep-issue
npm i
npm WARN ajv-keywords@3.1.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

supporting information:

  • npm -v prints: 5.6.0
  • node -v prints: 8.9.4
  • npm config get registry prints: https://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?: Windows 10
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Feb 21, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

See angular#9691 (comment) and npm/npm#19877 for more information.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Feb 21, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

This workaround should be safe for now since the only two packages that depend on `ajv-keywords@3.1.0` are `webpack` and `schema-utils`.

See angular#9691 (comment) and npm/npm#19877 for more information.

Fix angular#9691.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Feb 21, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

This workaround should be safe for now since the only two packages that depend on `ajv-keywords@3.1.0` are `webpack` and `schema-utils`.

See angular#9691 (comment) and npm/npm#19877 for more information.

Fix angular#9691.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Feb 21, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

This workaround should be safe for now since the only two packages that depend on `ajv-keywords@3.1.0` are `webpack` and `schema-utils`.

See angular#9691 (comment) and npm/npm#19877 for more information.

Fix angular#9691.
hansl pushed a commit to angular/angular-cli that referenced this issue Feb 21, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

This workaround should be safe for now since the only two packages that depend on `ajv-keywords@3.1.0` are `webpack` and `schema-utils`.

See #9691 (comment) and npm/npm#19877 for more information.

Fix #9691.
hansl pushed a commit to angular/angular-cli that referenced this issue Feb 22, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

This workaround should be safe for now since the only two packages that depend on `ajv-keywords@3.1.0` are `webpack` and `schema-utils`.

See #9691 (comment) and npm/npm#19877 for more information.

Fix #9691.
@bjornstar
Copy link

I have also created a simplified reproduction of this issue: @peer-deps-repro/main

This looks like another example of #15708

@filipesilva
Copy link
Author

@bjornstar it does look like the same, yes. I added a comment there.

@not-an-aardvark
Copy link
Contributor

We encountered this issue in ESLint too: eslint/eslint#10022

@ghost
Copy link

ghost commented Feb 27, 2018

Encountered this issue in standard too: standard/standard#1078 (comment)

@billyjanitsch
Copy link

This has been the case for awhile -- the npm hoisting algorithm doesn't currently consider whether a package's peer dependencies will be satisfied when hoisting it.

There was a quick/dirty fix in npm 5.2.0 but it was rolled back in 5.3.0 because they wanted to fix it properly & the naive fix broke users with questionable dependency workflows.

It's an uncommon scenario but once in awhile it comes up in a popular package (in this case, eslint). The npm CLI team is aware of it.

@jeffora
Copy link

jeffora commented Mar 6, 2018

It's also possible to hit this with @angular/cli with the following:

"devDependencies": {
  "@angular/cli": "^1.7.2",
  "@angular-devkit/core": "0.2.0"
}

This will cause @schematics/* packages to complain about missing peer dependency @angular-devkit/core and for ng * commands to crash.

Tested with npm@5.6.0 and npm@5.7.1.

Works correctly with yarn.

@1st
Copy link

1st commented Mar 14, 2018

I see the red highlight on this part:

  │ ├─┬ table@4.0.3
  │ │ ├─┬ UNMET PEER DEPENDENCY ajv@6.2.1
  │ │ │ ├── fast-deep-equal@1.1.0 deduped
  │ │ │ ├── fast-json-stable-stringify@2.0.0 deduped
  │ │ │ └── json-schema-traverse@0.3.1 deduped
  │ │ ├── ajv-keywords@3.1.0
  │ │ ├─┬ chalk@2.3.2
  │ │ │ ├── ansi-styles@3.2.1 deduped
  │ │ │ ├── escape-string-regexp@1.0.5 deduped
  │ │ │ └── supports-color@5.3.0 deduped
  │ │ ├── lodash@4.17.5 deduped
  │ │ ├─┬ slice-ansi@1.0.0
  │ │ │ └── is-fullwidth-code-point@2.0.0 deduped
  │ │ └── string-width@2.1.1 deduped
  │ └── text-table@0.2.0

and this message in the end:

npm ERR! peer dep missing: ajv@^6.0.0, required by ajv-keywords@3.1.0

dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
NPM hoists dependencies with peerDeps of their own, leading to unmet peer dependencies.

This workaround should be safe for now since the only two packages that depend on `ajv-keywords@3.1.0` are `webpack` and `schema-utils`.

See angular#9691 (comment) and npm/npm#19877 for more information.

Fix angular#9691.
sdirix added a commit to sdirix/jsonforms that referenced this issue May 28, 2018
* Update dependency versions of packages to be consistent
* Update packages to avoid security warnings
* Add ajv to dependencies to avoid bug
 npm/npm#19877
* Remove unnecessary package-lock.json files
edgarmueller pushed a commit to edgarmueller/jsonforms that referenced this issue Jun 15, 2018
* Update dependency versions of packages to be consistent
* Update packages to avoid security warnings
* Add ajv to dependencies to avoid bug
 npm/npm#19877
* Remove unnecessary package-lock.json files
edgarmueller pushed a commit to eclipsesource/jsonforms that referenced this issue Jun 15, 2018
* Update dependency versions of packages to be consistent
* Update packages to avoid security warnings
* Add ajv to dependencies to avoid bug
 npm/npm#19877
* Remove unnecessary package-lock.json files
eneufeld pushed a commit to eneufeld/jsonforms that referenced this issue Jun 21, 2018
* Update dependency versions of packages to be consistent
* Update packages to avoid security warnings
* Add ajv to dependencies to avoid bug
 npm/npm#19877
* Remove unnecessary package-lock.json files
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants