Skip to content

[BUG] npm ci installs an optional dependency which targets a different os than the host os #558

Closed
@JakeChampion

Description

@JakeChampion

What / Why

npm ci seems to install an optional dependency for the linux os when running on a mac and seems to install the optional dependency for mac when running on linux.

When

$ npm init -y; npm i [email protected]; npm ls; npm ci; npm ls
click to view output of above command
Wrote to /private/tmp/d/package.json:

{
"name": "d",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

[email protected] postinstall /private/tmp/d/node_modules/oax
node ./postinstall.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/oax/node_modules/oax-windows-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"win32","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/oax/node_modules/oax-linux-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"x64"} (current: {"os":"darwin","arch":"x64"})

  • [email protected]
    added 2 packages and audited 4 packages in 1.1s
    found 0 vulnerabilities

[email protected] /private/tmp/d
└─┬ [email protected]
├── [email protected]
├── UNMET OPTIONAL DEPENDENCY [email protected]
└── UNMET OPTIONAL DEPENDENCY [email protected]

npm WARN prepare removing existing node_modules/ before installation

[email protected] postinstall /private/tmp/d/node_modules/oax
node ./postinstall.js

added 3 packages in 0.722s
[email protected] /private/tmp/d
└─┬ [email protected]
├── [email protected]
├── [email protected]
└── UNMET OPTIONAL DEPENDENCY [email protected]

Where

  • n/a

How

Current Behavior

currently it looks like npm ci is broken for optional dependencies which use the os and arch fields of package.json

Steps to Reproduce

$ npm init -y; npm i [email protected]; npm ls; npm ci; npm ls

You should see that npm i works correctly and installs a single optional dependency for oax.
You should also see that npm ci works incorrectly and installs two of the optional dependencies for oax, this should never happen as each optional dependency is targeting a different operating system and architecture, it should be impossible to have more than one of the optional dependencies installed.

Expected Behavior

it should install oax-darwin when running on darwin and should install oax-linux when running on linux

Who

  • n/a

References

  • n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions