SBOM for Node.js products under the CRA

npm, Yarn and pnpm already record every package you ship. This page shows which file to build the SBOM from, the exact commands, and the one difference between the three that changes what ends up in it.

By NormavioUpdated

Build the SBOM from the lockfile (package-lock.json, yarn.lock or pnpm-lock.yaml), never from package.json, which only holds version ranges. With npm it is built in: npm sbom --sbom-format cyclonedx --omit dev --package-lock-only. The catch is development dependencies: only package-lock.json marks them, so with Yarn or pnpm 9 your test and build tools end up in the SBOM unless you do something about it.

Which file the SBOM comes from

Package managerFileFull dependency tree?Dev dependencies left out?
npmpackage-lock.json (v1 to v3)YesYes: marked "dev": true
Yarn (classic and Berry)yarn.lockYesNo: yarn.lock doesn't record which packages are dev-only
pnpmpnpm-lock.yaml (v5 to v9)YesOnly in lockfiles v5 and v6. Lockfile v9 (pnpm 9 and later) no longer marks them

How to generate it

With npm, no extra tools

npm has generated SBOMs since version 9.5. --package-lock-only reads the lockfile, so you don't need node_modules.

npm sbom --sbom-format cyclonedx --omit dev --package-lock-only > sbom.cdx.json

With the CRA Starter Kit tool (npm, Yarn and pnpm)

normavio_sbom.py reads all three lockfiles, skips node_modules, leaves out what the lockfile marks as dev, and writes a readable report for the technical file next to the SBOM.

python3 normavio_sbom.py ./app \
    --name "Nimbus Home app" --version 2.0.0 \
    --osv --out ./technical-file/sbom/2.0.0
# -> sbom.cdx.json and sbom-report.md

With other open-source generators

Syft, Trivy and cdxgen read all three lockfiles. For Yarn Berry, the CycloneDX project maintains an official Yarn plugin (cyclonedx-node-yarn).

syft dir:./app -o cyclonedx-json > sbom.cdx.json

What catches teams out

  • Electron apps. electron is usually a devDependency, but you ship it: it bundles Chromium and Node.js into your app. --omit dev drops it. Add it back, or generate without omitting dev and note why.
  • Dev tools with Yarn or pnpm 9. If your bundler, linter or test runner shows up as a component, this is why. Either accept it and say so in the report, or build the SBOM from a production-only install (for example pnpm install --prod) with a generator that reads node_modules.
  • Monorepos. Most generators, including the kit's tool, scan every lockfile under the folder you give them. Point them at the product you ship, not the repository root, or the SBOM mixes products.
  • Your own workspaces (@workspace: entries in yarn.lock) are your code, not third-party components. The kit's tool leaves them out.
  • package.json alone. ^5.10.0 is a range, not what you shipped. Without a lockfile the SBOM can't be reproduced.

What the CRA asks of this SBOM

  • Identify and document the components, including by drawing up an SBOM in a commonly used, machine-readable format, covering at least the top-level dependencies (Annex I, Part II, point 1).
  • Keep it in the technical documentation, one per product version (Annex VII, point 2).
  • Use it to find and fix vulnerabilities in those components without delay (Annex I, Part II, point 2).

The SBOM guide covers formats, fields and how to keep it alive.

Frequently asked questions

Do I need the whole node_modules tree or only direct dependencies?

The legal minimum is the top-level dependencies (Annex I, Part II, point 1), but the lockfile gives you the full tree for free and most vulnerabilities sit deep in it. Ship the full tree.

CycloneDX or SPDX for a Node.js product?

The CRA accepts any commonly used, machine-readable format. npm sbom writes both (--sbom-format spdx). CycloneDX is the usual choice when the SBOM drives vulnerability tracking.

Does the frontend bundle need its own SBOM?

Usually not: what ends up in the browser bundle comes from the same lockfile. If the frontend is a separate product with its own lockfile, generate one per lockfile and per release.