[BUG] OS specific module breaks workspace installation
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
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
When workspace config contains a package that requests an specific os/cpu, if current platform doesn't match that requirement, npm will panic and throw 'EBADPLATFORM' error.
Currently we can't mark a workspace package "optional" in any ways. In order to finish the installation process, we need to use "--force" flag.
Packages that need to build sub n-api platform-specific packages like esbuild face this issue.
Expected Behavior
Let npm have a config to consider a workspace package "optional".
One method to archive that is using optionalDependencies config:
# root pacage.json
{
"workspaces": ["a"],
"optionalDependencies": {
"a": "*"
}
}
Or add another config like the peerDependenciesMeta:
# root pacage.json
{
"workspaces": ["a"],
"workspacesMeta": {
"a": {
"optional": true
}
}
}
Steps To Reproduce
For example:
# root pacage.json
{
"workspaces": ["a"]
}
# a/package.json
{
"name": "a",
"os": [
"darwin"
],
"cpu": [
"x64"
]
}
When trying to run npm install on an different platform, error like below will be thrown:

Environment
- npm: 9.4.0
- Node.js: 16.18.1
- OS Name: MacOS 13.0.1
- System Model Name: Macbook Pro 16'
- npm config:
unrelated
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the root package.json and a/package.json examples, then reproduce npm install with the workspace package restricted to darwin and x64 on a nonmatching platform. Compare the optionalDependencies and workspacesMeta proposals, and consider the behavior needed for installation to complete without EBADPLATFORM.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100