fix(npm): prevent workspace hoisting and ignore npm ls errors during BOM generation - #5855
fix(npm): prevent workspace hoisting and ignore npm ls errors during BOM generation#5855Rykee wants to merge 3 commits into
Conversation
…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>
8101c68 to
5968948
Compare
|
i can also include one more use case where yarn.lock and this works fine since yarn resolves this to highest version and uses since sbom is generated after the dependency installation we can ignore these |
Problem
When
npmExecuteScriptsgenerates a CycloneDX BOM for npm workspace projects on Node 24 / npm v11+, it fails withELSPROBLEMSexit code 254.Two issues combine to cause this:
Extraneous packages (workspace + npm v11+):
cyclonedx-npmis installed vianpm install --prefix ./tmp, but npm hoists its native dependencies (@emnapi/core,@napi-rs/wasm-runtime, etc.) into the workspace rootnode_modules. On npm v11+ (Node 24),npm lsexits non-zero onELSPROBLEMS. Non-workspace projects are unaffected since hoisting doesn't occur outside a workspace context.Invalid packages (workspace + npm overrides): Packages overridden via npm
overridesfor security fixes are reported asinvalidbynpm lsbecause 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-npmto fail fatally since it treats anynpm lsnon-zero exit as fatal.Fix
--no-workspacesto the install command to prevent hoisting. No-op for non-workspace projects.--ignore-npm-errorsto the run command to toleratenpm lswarnings in workspace setups with overrides.Testing
Reproduced the failure locally using the exact SAP Docker image (
node:24.16.0, npm11.13.0) and verified both flags together fix it — exit code 0 and BOM generated successfully. Unit tests updated and passing.Question
@cyclonedx/cyclonedx-npmis pinned to2.1.0while the latest is6.0.0. We tested6.0.0with just--ignore-npm-errors(no--no-workspacesneeded) and it also works. Is there a reason for staying on2.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.