Skip to content

[BUG] Installing package with optional peer dependencies reports conflicts incorrectly #8416

@gkjohnson

Description

@gkjohnson

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

I'm using optional peer dependencies for maintaining the 3DTilesRenderer package to ensure only the dependencies that users need are installed. As far as I can tell there are no conflicts within the peer dependency definitions but when installing from npm in a new project via npm install 3d-tiles-renderer I get the following error:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error   peer react@"*" from [email protected]
npm error   node_modules/expo
npm error     peerOptional expo@">=43.0" from @react-three/[email protected]
npm error     node_modules/@react-three/fiber
npm error       peerOptional @react-three/fiber@"^8.17.9" from [email protected]
npm error       node_modules/3d-tiles-renderer
npm error         3d-tiles-renderer@"*" from the root project
npm error     peer expo@"*" from @expo/[email protected]
npm error     node_modules/@expo/dom-webview
npm error       peerOptional @expo/dom-webview@"*" from [email protected]
npm error     3 more (expo-asset, expo-file-system, expo-gl)
npm error   peer react@"*" from @expo/[email protected]
npm error   node_modules/@expo/dom-webview
npm error     peerOptional @expo/dom-webview@"*" from [email protected]
npm error   5 more (react-native, react-native-webview, expo-asset, expo-gl, react-native-web)
npm error
npm error Could not resolve dependency:
npm error peerOptional react@"^18.3.1" from [email protected]
npm error node_modules/3d-tiles-renderer
npm error   3d-tiles-renderer@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.

When specifying the same packages as "dependencies" in the same package.json, though, and installing them there are no conflicts. So it seems the optional peer dependencies are being reported incorrectly.

Expected Behavior

No errors should be reported when installing a package with optional peer dependencies when there are no conflicts. It's not clear to me why conflicts are being checked at all when the project has not separately installed the peer dependencies.

Steps To Reproduce

  1. Create a new folder
  2. Run npm init
  3. Run npm install 3d-tiles-renderer
  4. See error reporting conflicts even though no other packages are installed and the package has no required dependencies other than 1 peer dependency (three.js) which has no dependencies itself.

Environment

  • npm: 11.4.2
  • Node.js: 24.3.0
  • OS Name: Sequoia 15.5
  • System Model Name: 2021 M1 Macbook Pro
  • npm config:
; "user" config from /Users/garrett/.npmrc

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /Users/garrett/.nvm/versions/node/v24.3.0/bin/node
; node version = v24.3.0
; npm local prefix = /Users/garrett/Desktop/test
; npm version = 11.4.2
; cwd = /Users/garrett/Desktop/test
; HOME = /Users/garrett
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions