cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] Optional peer dependency influences node_modules layout

Open tkalmar opened this issue 11 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

Given the following projects: Project A

{                                                                                                                                                                                   
  "name": "projecta",                                                                                                                                                               
  "version": "1.0.0",                                                                                                                                                               
  "main": "index.js",                                                                                                                                                               
  "dependencies": {                                                                                                                                                                 
    "prettier-plugin-organize-imports": "4.1.0"                                                                                                                                     
  }                                                                                                                                                                                 
} 

Project B

{                                                                                                                                                                                   
  "name": "projectb",                                                                                                                                                               
  "version": "1.0.0",                                                                                                                                                               
  "main": "index.js",                                                                                                                                                               
  "dependencies": {                                                                                                                                                                 
    "projecta": "1.0.0",
   "typescript: "4.9.5"                                                                                                                                     
  }                                                                                                                                                                                 
}

When installing packages in Project B prettier-plugin-organize-imports is located under node_modules/projecta/node_modules because prettier-plugin-organize-imports contains

"peerDependencies": {
    "@vue/language-plugin-pug": "^2.0.24",
    "prettier": ">=2.0",
    "typescript": ">=2.9",
    "vue-tsc": "^2.0.24"
  },
  "peerDependenciesMeta": {
    "@vue/language-plugin-pug": {
      "optional": true
    },
    "vue-tsc": {
      "optional": true
    }
  },

and vue-tsc has a peer-dependency on typescript 5.0.0

"peerDependencies": {
		"typescript": ">=5.0.0"
	},

When project B is moved to typescript 5.0.0 then prettier-plugin-organize-imports is located under node_modules/ directly. To reproduce:

  • npm pack in projectA
  • npm install ../projectA/projecta-1.0.0.tgz

After changing the typescript Version in project B to 5.6.2 the layout of node_modules changes One workaround is to override the vue-tsc dependency of prettier-plugin-organize-imports to vue-tsc in version 2.0.20 which has a peer dependency to typescript "*".

Expected Behavior

The optional peer-dependency should not influence the layout of node_modules if not present. So the layout of node_modules should be the same in both cases (typescript 4.9.5 and typescript 5.0.0).

Steps To Reproduce

  1. npm pack in projectA
  2. npm install ../projectA/projecta-1.0.0.tgz
  3. observe node modules layout
  4. update typescript dependency in project b
  5. after a clean install in project b the node_modules structure changes

Environment

  • npm: 10.8.1 (also in 9.8.1 and 10.9.0)
  • Node.js: tried 18 /20 /22
  • OS Name: Ubuntu 20.04
  • System Model Name: Lenovo Thinkpad
  • npm config:
; node bin location = /home/XXX/.nvm/versions/node/v22.11.0/bin/node
; node version = v22.11.0
; npm local prefix = /home/XXX/work/npm_repro/projectB
; npm version = 10.9.0
; cwd = /home/XXX/work/npm_repro/projectB
; HOME = /home/XXX
; Run `npm config ls -l` to show all defaults.

tkalmar avatar Jan 13 '25 13:01 tkalmar