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] npm does not include prerelease versions when matching with peerDependencies #7303

Closed
2 tasks done
pulges opened this issue Mar 20, 2024 · 5 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x

Comments

@pulges
Copy link

pulges commented Mar 20, 2024

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

In a private library I have

"peerDependencies": {
    "my-package": ">=4"
}

and I get "Could not resolve dependency" error when trying to install snapshot versions of library llike

4.3.1-master.1710852533570

The issue has been reported before (#4958) but closed without actually explaining why npm has to diverge from semver specifications and have such undocumented side-effect.

The support for pre-release versions in peerDependencies is really required, when multiple libraries are being developed in conjunction to modularize development environment. Currently solutions to use incorrect "*" as peerDependency criteria or overrides, are very cumbersome to use between multiple developers and can also result in these lines being forgotten and leaking into production code.

Expected Behavior

In peerDependencies conditions should match also prerelease versions.

Steps To Reproduce

No response

Environment

  • npm: 10.5.0
  • Node.js: v20.11.0
  • OS Name: Ubuntu
  • System Model Name: 23.10
@pulges pulges added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Mar 20, 2024
@ljharb
Copy link
Contributor

ljharb commented Mar 20, 2024

This is by design. Prereleases are never included unless you use a more explicit prerelease range (like ^4.3.1-0, i believe)

@pulges
Copy link
Author

pulges commented Mar 20, 2024

I do understand, why npm should not pick a prerelease package automatically during installation. But throwing an error message for handpicked prerelease package that actually matches, seems like a totally different issue and I still do not quite underatand the reasons behind this design choice.

@ljharb
Copy link
Contributor

ljharb commented Mar 20, 2024

If you’re trying to test prereleases, you should use overrides. If a range includes them, all users would get them by default.

@wraithgar
Copy link
Member

Yes, this is by design. Pre-releases have to be explicitly asked for to be installed. By definition that version has not been released. It would be inappropriate for users to get it before it's ready.

Folks have solved the issue of testing multiple packages in prerelease mode with overrides, npm link, or workspaces. It is admittedly a hard problem to solve, but breaking existing installations by including prereleases is not the solution.

@Sophos-Elias-Vasylenko
Copy link

Yes, this is by design. Pre-releases have to be explicitly asked for to be installed. By definition that version has not been released. It would be inappropriate for users to get it before it's ready.

FWIW I believe the argument here is that they are being explicitly asked to be installed in this case, and that users would categorically not be exposed to pre-releases by default in this scenario.

A peer dependency directly listed on the current package should still resolve to non-pre-release versions according to the current behaviour. I think what is being suggested is that a transitive peer dependency can be satisfied by a pre-release version iff a pre-release version is explicitly requested by the host app.

Others arriving here should see the RFC here for more discussion npm/rfcs#397

I'm not asking to reopen the ticket, and I realise most of the people here are involved in the RFC discussion and aware of these arguments :). I'm mainly just commenting for the benefit of future searches as this was one of the first tickets I came across when searching for answers about this. Hope that's okay.

Cheers

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 Release 10.x
Projects
None yet
Development

No branches or pull requests

4 participants