Skip to content

fix(npm): prevent workspace hoisting and ignore npm ls errors during BOM generation - #5855

Open
Rykee wants to merge 3 commits into
SAP:masterfrom
Rykee:fix/npm-bom-workspace-hoisting
Open

fix(npm): prevent workspace hoisting and ignore npm ls errors during BOM generation#5855
Rykee wants to merge 3 commits into
SAP:masterfrom
Rykee:fix/npm-bom-workspace-hoisting

Conversation

@Rykee

@Rykee Rykee commented Jul 28, 2026

Copy link
Copy Markdown

Problem

When npmExecuteScripts generates a CycloneDX BOM for npm workspace projects on Node 24 / npm v11+, it fails with ELSPROBLEMS exit code 254.

Two issues combine to cause this:

  1. Extraneous packages (workspace + npm v11+): cyclonedx-npm is installed via npm install --prefix ./tmp, but npm hoists its native dependencies (@emnapi/core, @napi-rs/wasm-runtime, etc.) into the workspace root node_modules. On npm v11+ (Node 24), npm ls exits non-zero on ELSPROBLEMS. Non-workspace projects are unaffected since hoisting doesn't occur outside a workspace context.

  2. Invalid packages (workspace + npm overrides): Packages overridden via npm overrides for security fixes are reported as invalid by npm ls because the installed version doesn't exactly match what the dependent package declared. This is a structural consequence of npm overrides and cannot be avoided without removing the security fix.

Both cause cyclonedx-npm to fail fatally since it treats any npm ls non-zero exit as fatal.

Fix

  • Add --no-workspaces to the install command to prevent hoisting. No-op for non-workspace projects.
  • Add --ignore-npm-errors to the run command to tolerate npm ls warnings in workspace setups with overrides.

Testing

Reproduced the failure locally using the exact SAP Docker image (node:24.16.0, npm 11.13.0) and verified both flags together fix it — exit code 0 and BOM generated successfully. Unit tests updated and passing.

Question

@cyclonedx/cyclonedx-npm is pinned to 2.1.0 while the latest is 6.0.0. We tested 6.0.0 with just --ignore-npm-errors (no --no-workspaces needed) and it also works. Is there a reason for staying on 2.1.0? If upgrading is welcome, the fix could be simplified to just the version bump + --ignore-npm-errors. Happy to submit a follow-up or update this PR.

@Rykee
Rykee requested review from a team as code owners July 28, 2026 14:32
@cla-assistant

cla-assistant Bot commented Jul 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Rykee added 2 commits July 28, 2026 16:47
…BOM generation

When running cyclonedx-npm BOM generation in npm workspace projects, the
cyclonedx-npm package installed via --prefix gets its native dependencies
hoisted into the workspace root node_modules. This causes npm ls to report
them as extraneous, resulting in a non-zero exit code with npm v11+.

Additionally, packages overridden via npm overrides (e.g. for security fixes)
are reported as invalid by npm ls because the installed version does not
exactly match the version declared by the dependent package.

Fix by:
- Adding --no-workspaces to the install command to prevent dependency hoisting
- Adding --ignore-npm-errors to the cyclonedx-npm run command to tolerate
  npm ls warnings in workspace setups with overrides

Signed-off-by: Márk Mátray <mark.matray@sap.com>
Signed-off-by: Rykee <matrayz@gmail.com>
…rs flags

Signed-off-by: Márk Mátray <mark.matray@sap.com>
Signed-off-by: Rykee <matrayz@gmail.com>
@Rykee
Rykee force-pushed the fix/npm-bom-workspace-hoisting branch from 8101c68 to 5968948 Compare July 28, 2026 14:48
@anilkeshav27

anilkeshav27 commented Jul 30, 2026

Copy link
Copy Markdown
Member

i can also include one more use case where --ignore-npm-errors make sense when using yarn.lock, since yarn is used for installing dependencies and cyclonedx is using npm there are descrepancies how they both resolve depdencies e.g

yarn.lock
lodash@4.17.23, lodash@4.18.1, lodash@^4.17.10, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.23, lodash@^4.18.1:

and this works fine since yarn resolves this to highest version and uses lodash@4.18.1 and also brings this in node_modules, but npm ls will complain as it sees a fixed version lodash@4.17.23 and then complains it is not installed

npm error code ELSPROBLEMS
  npm error invalid: lodash@4.18.1

since sbom is generated after the dependency installation we can ignore these ELSPROBLEMS and any dependencies problems are be caught earlier during dependency installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants