Skip to content

[BUG] Inconsistent dependancies versions for sub-dependancies due to deduplication  #5202

Description

@gmrchk

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Consider the following scenario (also available at https://github.com/gplopes/npm-dedupe-peer-deps for repro).

// main-app
"package-a": "file:../package-a",
"package-b": "file:../package-b",
"graphql": "15.0.0"
// package=a
"graphql": "16.5.0",
"@graphql-tools/schema": "8.3.8", // peerDependency: graphql "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
"@graphql-tools/stitch": "8.6.12" // peerDependency: graphql "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
// package-b
"graphql": "15.0.0"

The npm install will produce following node_modules structure:

// node_modules (root)"graphql": "15.0.0"// deduped "@graphql-tools/schema": "8.3.8"// issue lays here where this package now references the root graphql which is a different version than the one install in package-a"@graphql-tools/stitch": "8.6.12"└───project-a/node_modules└───"graphql": "16.5.0"// not deduped└───project-b/node_modules└───"graphql": "15.0.0"// deduped (using root package)

@graphql-tools/schema uses the wrong graphql version from the root project (main-app).
The version of graphql for @graphql-tools/schema should be decided by the actual consumer of @graphql-tools/schema, which in this case is project-a, not main-app.

Expected Behavior

npm install should produce following node_modules stucture:

// node_modules (root)
│ "graphql": "15.0.0" // deduped │
└───project-a/node_modules
│ └───"graphql": "16.5.0"
│ └───"@graphql-tools/schema": "8.3.8" // should not be deduped as the project depends on graphql: 16.5.0
│ └───"@graphql-tools/stitch": "8.6.12" // should not be deduped as the project depends on graphql: 16.5.0
│ └───project-b/node_modules
└───"graphql": "15.0.0" // deduped (using root package)

Deduplication should consider the version of graphql installed in project-a to be the required version for its dependancies defining graphql as peer dependancy, like @graphql-tools/schema in this scenario.

Alternatively, sub dependancies with peer dependancies defined should not be deduped at all for version safety.

Steps To Reproduce

  1. Clone https://github.com/gplopes/npm-dedupe-peer-deps.
  2. Run npm i.
  3. Check the node_modules folder where @graphql-tools/schema and @graphql-tools/stitch are deduped to the root node_modules.

Environment

  • npm: 8.15.0
  • Node.js: 16.15.1
  • OS Name: MacOS Monterey
  • System Model Name: 12.4
  • npm config:
; "user" config from /Users/georgymarchuk/.npmrc
@pipedrive:registry = "https://npm-registry-proxy.pipedrive.tools" //npm-registry-proxy.pipedrive.tools/:_authToken = (protected) //npm-registry-proxy.pipedrive.tools/:always-auth = true //registry.npmjs.org/:_authToken = (protected) ; node bin location = /Users/georgymarchuk/.nvm/versions/node/v16.15.1/bin/node; node version = v16.15.1; npm local prefix = /Users/georgymarchuk/git/npm-dedupe-peer-deps; npm version = 8.15.0; cwd = /Users/georgymarchuk/git/npm-dedupe-peer-deps; HOME = /Users/georgymarchuk; Run `npm config ls -l` to show all defaults.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions