npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] OS specific module breaks workspace installation #6138

Open MondoGao opened 1 year ago

MondoGao commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

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: CleanShot 2023-02-07 at 10 12 55

Environment

MondoGao commented 1 year ago

Related issue in yarn 1: https://github.com/yarnpkg/yarn/issues/5951

DevCon1100 commented 1 year ago

Access

DevCon1100 commented 1 year ago

Access

fritzy commented 1 year ago

This isn't really a bug, so it probably be in the npm/rfcs repo, but it also feels like an oversight. We should probably do this.

kasperisager commented 1 year ago

I just hit this as well with a monorepo that contains OS and architecture specific packages. As a user of npm, it definitely feels like a bug and renders the workspace feature unusable for such monorepos.

loozhengyuan commented 4 months ago

Just encountered the same issue as well and it really does make the workspace rather unusable. It also feels quite hacky having to use --force to bypass this error.