Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Optional peer dependency influences node_modules layout #8028

Open
2 tasks done
tkalmar opened this issue Jan 13, 2025 · 0 comments
Open
2 tasks done

[BUG] Optional peer dependency influences node_modules layout #8028

tkalmar opened this issue Jan 13, 2025 · 0 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@tkalmar
Copy link

tkalmar commented Jan 13, 2025

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

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 tkalmar added Bug thing that needs fixing Needs Triage needs review for next steps labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

1 participant