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] Local path peerDependencies behave like dependencies #7171

Closed
2 tasks done
DanKaplanSES opened this issue Jan 23, 2024 · 4 comments
Closed
2 tasks done

[BUG] Local path peerDependencies behave like dependencies #7171

DanKaplanSES opened this issue Jan 23, 2024 · 4 comments
Labels
Bug thing that needs fixing Release 10.x

Comments

@DanKaplanSES
Copy link
Contributor

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

App depends on Lib. Lib has a peerDependency on jsdom.

I believe App's jsdom stack traces should come from app-package because jsdom is a peerDependency of lib-package. That is not the case:

C:\MyPackages\jsdom-sandbox\lib-package\node_modules\jsdom\lib\api.js:321
        throw new TypeError("resources must be an instance of ResourceLoader");
              ^

TypeError: resources must be an instance of ResourceLoader
    at resourcesToResourceLoader (C:\MyPackages\jsdom-sandbox\lib-package\node_modules\jsdom\lib\api.js:321:15)
    at transformOptions (C:\MyPackages\jsdom-sandbox\lib-package\node_modules\jsdom\lib\api.js:263:46)
    at new JSDOM (C:\MyPackages\jsdom-sandbox\lib-package\node_modules\jsdom\lib\api.js:34:15)
    at JSDOM.fromFile (C:\MyPackages\jsdom-sandbox\lib-package\node_modules\jsdom\lib\api.js:152:12)

Explicitly adding jsdom as a dependency to app-package makes no difference.

Expected Behavior

C:\MyPackages\jsdom-sandbox\app-package\node_modules\jsdom\lib\api.js:321
        throw new TypeError("resources must be an instance of ResourceLoader");
              ^

TypeError: resources must be an instance of ResourceLoader
    at resourcesToResourceLoader (C:\MyPackages\jsdom-sandbox\app-package\node_modules\jsdom\lib\api.js:321:15)
    at transformOptions (C:\MyPackages\jsdom-sandbox\app-package\node_modules\jsdom\lib\api.js:263:46)
    at new JSDOM (C:\MyPackages\jsdom-sandbox\app-package\node_modules\jsdom\lib\api.js:34:15)
    at JSDOM.fromFile (C:\MyPackages\jsdom-sandbox\app-package\node_modules\jsdom\lib\api.js:152:12)

Steps To Reproduce

  1. Git clone https://github.com/DanKaplanSES/jsdom-sandbox/tree/local-path-peer-dependencies-reproducible
  2. cd local-path-peer-dependencies-reproducible
  3. ./setup.sh
  4. ./npma.sh run exec

This is related to #5108

Environment

  • npm: 10.3.0
  • Node.js: 20.10.0
  • OS Name: Windows
  • System Model Name: 10
  • npm config:
; "builtin" config from C:\Users\myuser\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\myuser\\AppData\\Roaming\\npm"

; "user" config from C:\cygwin64\home\myuser\.npmrc

//registry.npmjs.org/:_authToken = (protected)
registry = "https://registry.npmjs.org/"
script-shell = "C:\\cygwin64\\bin\\bash.exe"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v20.10.0
; npm local prefix = C:\my-projects\jsdom-sandbox
; npm version = 10.3.0
; cwd = C:\my-projects\jsdom-sandbox
; HOME = C:\cygwin64\home\myuser
; Run `npm config ls -l` to show all defaults.
@DanKaplanSES
Copy link
Contributor Author

This is an issue in yarn too. Fortunately, a comment provides a workaround that works in both package managers:

for those wondering; I ran into the same issue and used yalc to fix my problem.

@kchindam-infy kchindam-infy added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Jan 28, 2025
@kchindam-infy kchindam-infy removed the Priority 2 secondary priority issue label Mar 3, 2025
@kchindam-infy
Copy link

This issue can be resolved by using --install-links during npm install. Eg: npm i --install -links. --install-links option helps in installing the local dependenciesas packages instead of creating a symlink in the node_modules of app-package. Ref: https://docs.npmjs.com/cli/v8/commands/npm-install

@DanKaplanSES
Copy link
Contributor Author

That worked for me!

There's no documentation about using --install-links without an argument. Does that make it true or false?


That said, why should --install-links change the behavior of peerDependencies? That still seems like a bug to me: whether lib is a symlink or not, peerDependencies should act like peerDependencies, no?

@kchindam-infy
Copy link

No argument in this case is equivalent to true.
'npm i --install-links' is equivalent to 'npm i --install-links=true'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 10.x
Projects
None yet
Development

No branches or pull requests

2 participants