[Bug?]: Yarn v3 Incompatibility with 'npm:' prefix in Peer Dependencies
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
I am experiencing an issue with Yarn v3 when using the 'npm:' prefix to alias a package in peer dependencies.
In my package.json, I have aliased react-intl as react-intl-next:
"react-intl-next": "npm:react-intl@^5.18.1"
However, when I run yarn install, I get the following error:
$packageName: Invalid dependency range for 'react-intl-next'
I believe this is because Yarn v3 is not able to parse the 'npm:' prefix in the version range for peer dependencies. Here is the relevant code from the Yarn v3 binary:
if (typeof range !== `string` || !range.startsWith(WorkspaceResolver.protocol) && !validRange(range)) {
errors.push(new Error(`Invalid dependency range for '${name}'`));
range = `*`;
}
This issue is preventing me from being able to correctly install my dependencies. I need to keep the 'npm:' prefix because I need to use a different version of react-intl than the one specified in the package's dependencies or peerDependencies.
Is there a way to make Yarn v3 compatible with the 'npm:' prefix in peer dependencies?
To reproduce
- Create a
package.jsonfile with the following content:
{
"name": "my-project",
"version": "1.0.0",
"peerDependencies": {
"react-intl-next": "npm:react-intl@^5.18.1"
}
}
- Run
yarn install - Notice the error message:
Invalid dependency range for 'react-intl-next'
Environment
- macOS Sonoma 14.3
- Node.js version: 18.17.0
- Yarn version: 3.6.1
Additional context
No response
This isn't a bug. Peer dependencies only check the version of the package that users provide, not their provenance (ie it doesn't matter whether they come from npm, git, or anything else). As a result, putting anything else than a semver range here will error.
This issue is preventing me from being able to correctly install my dependencies. I need to keep the 'npm:' prefix because I need to use a different version of
react-intlthan the one specified in the package'sdependenciesorpeerDependencies.
You'll have to rename your own copy of react-intl in your own package. Peer dependencies don't support renaming the packages they lift up.
I see. Thanks for the the suggestion @arcanis.
Hi! 👋
It seems like this issue as been marked as probably resolved, or missing important information blocking its progression. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it.