11cb0ef41Sopenharmony_ci--- 21cb0ef41Sopenharmony_cititle: npm-sbom 31cb0ef41Sopenharmony_cisection: 1 41cb0ef41Sopenharmony_cidescription: Generate a Software Bill of Materials (SBOM) 51cb0ef41Sopenharmony_ci--- 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci### Synopsis 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci```bash 101cb0ef41Sopenharmony_cinpm sbom 111cb0ef41Sopenharmony_ci``` 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci### Description 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciThe `npm sbom` command generates a Software Bill of Materials (SBOM) listing the 161cb0ef41Sopenharmony_cidependencies for the current project. SBOMs can be generated in either 171cb0ef41Sopenharmony_ci[SPDX](https://spdx.dev/) or [CycloneDX](https://cyclonedx.org/) format. 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci### Example CycloneDX SBOM 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci```json 221cb0ef41Sopenharmony_ci{ 231cb0ef41Sopenharmony_ci "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json", 241cb0ef41Sopenharmony_ci "bomFormat": "CycloneDX", 251cb0ef41Sopenharmony_ci "specVersion": "1.5", 261cb0ef41Sopenharmony_ci "serialNumber": "urn:uuid:09f55116-97e1-49cf-b3b8-44d0207e7730", 271cb0ef41Sopenharmony_ci "version": 1, 281cb0ef41Sopenharmony_ci "metadata": { 291cb0ef41Sopenharmony_ci "timestamp": "2023-09-01T00:00:00.001Z", 301cb0ef41Sopenharmony_ci "lifecycles": [ 311cb0ef41Sopenharmony_ci { 321cb0ef41Sopenharmony_ci "phase": "build" 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci ], 351cb0ef41Sopenharmony_ci "tools": [ 361cb0ef41Sopenharmony_ci { 371cb0ef41Sopenharmony_ci "vendor": "npm", 381cb0ef41Sopenharmony_ci "name": "cli", 391cb0ef41Sopenharmony_ci "version": "10.1.0" 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci ], 421cb0ef41Sopenharmony_ci "component": { 431cb0ef41Sopenharmony_ci "bom-ref": "simple@1.0.0", 441cb0ef41Sopenharmony_ci "type": "library", 451cb0ef41Sopenharmony_ci "name": "simple", 461cb0ef41Sopenharmony_ci "version": "1.0.0", 471cb0ef41Sopenharmony_ci "scope": "required", 481cb0ef41Sopenharmony_ci "author": "John Doe", 491cb0ef41Sopenharmony_ci "description": "simple react app", 501cb0ef41Sopenharmony_ci "purl": "pkg:npm/simple@1.0.0", 511cb0ef41Sopenharmony_ci "properties": [ 521cb0ef41Sopenharmony_ci { 531cb0ef41Sopenharmony_ci "name": "cdx:npm:package:path", 541cb0ef41Sopenharmony_ci "value": "" 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci ], 571cb0ef41Sopenharmony_ci "externalReferences": [], 581cb0ef41Sopenharmony_ci "licenses": [ 591cb0ef41Sopenharmony_ci { 601cb0ef41Sopenharmony_ci "license": { 611cb0ef41Sopenharmony_ci "id": "MIT" 621cb0ef41Sopenharmony_ci } 631cb0ef41Sopenharmony_ci } 641cb0ef41Sopenharmony_ci ] 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci }, 671cb0ef41Sopenharmony_ci "components": [ 681cb0ef41Sopenharmony_ci { 691cb0ef41Sopenharmony_ci "bom-ref": "lodash@4.17.21", 701cb0ef41Sopenharmony_ci "type": "library", 711cb0ef41Sopenharmony_ci "name": "lodash", 721cb0ef41Sopenharmony_ci "version": "4.17.21", 731cb0ef41Sopenharmony_ci "scope": "required", 741cb0ef41Sopenharmony_ci "author": "John-David Dalton", 751cb0ef41Sopenharmony_ci "description": "Lodash modular utilities.", 761cb0ef41Sopenharmony_ci "purl": "pkg:npm/lodash@4.17.21", 771cb0ef41Sopenharmony_ci "properties": [ 781cb0ef41Sopenharmony_ci { 791cb0ef41Sopenharmony_ci "name": "cdx:npm:package:path", 801cb0ef41Sopenharmony_ci "value": "node_modules/lodash" 811cb0ef41Sopenharmony_ci } 821cb0ef41Sopenharmony_ci ], 831cb0ef41Sopenharmony_ci "externalReferences": [ 841cb0ef41Sopenharmony_ci { 851cb0ef41Sopenharmony_ci "type": "distribution", 861cb0ef41Sopenharmony_ci "url": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz" 871cb0ef41Sopenharmony_ci }, 881cb0ef41Sopenharmony_ci { 891cb0ef41Sopenharmony_ci "type": "vcs", 901cb0ef41Sopenharmony_ci "url": "git+https://github.com/lodash/lodash.git" 911cb0ef41Sopenharmony_ci }, 921cb0ef41Sopenharmony_ci { 931cb0ef41Sopenharmony_ci "type": "website", 941cb0ef41Sopenharmony_ci "url": "https://lodash.com/" 951cb0ef41Sopenharmony_ci }, 961cb0ef41Sopenharmony_ci { 971cb0ef41Sopenharmony_ci "type": "issue-tracker", 981cb0ef41Sopenharmony_ci "url": "https://github.com/lodash/lodash/issues" 991cb0ef41Sopenharmony_ci } 1001cb0ef41Sopenharmony_ci ], 1011cb0ef41Sopenharmony_ci "hashes": [ 1021cb0ef41Sopenharmony_ci { 1031cb0ef41Sopenharmony_ci "alg": "SHA-512", 1041cb0ef41Sopenharmony_ci "content": "bf690311ee7b95e713ba568322e3533f2dd1cb880b189e99d4edef13592b81764daec43e2c54c61d5c558dc5cfb35ecb85b65519e74026ff17675b6f8f916f4a" 1051cb0ef41Sopenharmony_ci } 1061cb0ef41Sopenharmony_ci ], 1071cb0ef41Sopenharmony_ci "licenses": [ 1081cb0ef41Sopenharmony_ci { 1091cb0ef41Sopenharmony_ci "license": { 1101cb0ef41Sopenharmony_ci "id": "MIT" 1111cb0ef41Sopenharmony_ci } 1121cb0ef41Sopenharmony_ci } 1131cb0ef41Sopenharmony_ci ] 1141cb0ef41Sopenharmony_ci } 1151cb0ef41Sopenharmony_ci ], 1161cb0ef41Sopenharmony_ci "dependencies": [ 1171cb0ef41Sopenharmony_ci { 1181cb0ef41Sopenharmony_ci "ref": "simple@1.0.0", 1191cb0ef41Sopenharmony_ci "dependsOn": [ 1201cb0ef41Sopenharmony_ci "lodash@4.17.21" 1211cb0ef41Sopenharmony_ci ] 1221cb0ef41Sopenharmony_ci }, 1231cb0ef41Sopenharmony_ci { 1241cb0ef41Sopenharmony_ci "ref": "lodash@4.17.21", 1251cb0ef41Sopenharmony_ci "dependsOn": [] 1261cb0ef41Sopenharmony_ci } 1271cb0ef41Sopenharmony_ci ] 1281cb0ef41Sopenharmony_ci} 1291cb0ef41Sopenharmony_ci``` 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ci### Example SPDX SBOM 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci```json 1341cb0ef41Sopenharmony_ci{ 1351cb0ef41Sopenharmony_ci "spdxVersion": "SPDX-2.3", 1361cb0ef41Sopenharmony_ci "dataLicense": "CC0-1.0", 1371cb0ef41Sopenharmony_ci "SPDXID": "SPDXRef-DOCUMENT", 1381cb0ef41Sopenharmony_ci "name": "simple@1.0.0", 1391cb0ef41Sopenharmony_ci "documentNamespace": "http://spdx.org/spdxdocs/simple-1.0.0-bf81090e-8bbc-459d-bec9-abeb794e096a", 1401cb0ef41Sopenharmony_ci "creationInfo": { 1411cb0ef41Sopenharmony_ci "created": "2023-09-01T00:00:00.001Z", 1421cb0ef41Sopenharmony_ci "creators": [ 1431cb0ef41Sopenharmony_ci "Tool: npm/cli-10.1.0" 1441cb0ef41Sopenharmony_ci ] 1451cb0ef41Sopenharmony_ci }, 1461cb0ef41Sopenharmony_ci "documentDescribes": [ 1471cb0ef41Sopenharmony_ci "SPDXRef-Package-simple-1.0.0" 1481cb0ef41Sopenharmony_ci ], 1491cb0ef41Sopenharmony_ci "packages": [ 1501cb0ef41Sopenharmony_ci { 1511cb0ef41Sopenharmony_ci "name": "simple", 1521cb0ef41Sopenharmony_ci "SPDXID": "SPDXRef-Package-simple-1.0.0", 1531cb0ef41Sopenharmony_ci "versionInfo": "1.0.0", 1541cb0ef41Sopenharmony_ci "packageFileName": "", 1551cb0ef41Sopenharmony_ci "description": "simple react app", 1561cb0ef41Sopenharmony_ci "primaryPackagePurpose": "LIBRARY", 1571cb0ef41Sopenharmony_ci "downloadLocation": "NOASSERTION", 1581cb0ef41Sopenharmony_ci "filesAnalyzed": false, 1591cb0ef41Sopenharmony_ci "homepage": "NOASSERTION", 1601cb0ef41Sopenharmony_ci "licenseDeclared": "MIT", 1611cb0ef41Sopenharmony_ci "externalRefs": [ 1621cb0ef41Sopenharmony_ci { 1631cb0ef41Sopenharmony_ci "referenceCategory": "PACKAGE-MANAGER", 1641cb0ef41Sopenharmony_ci "referenceType": "purl", 1651cb0ef41Sopenharmony_ci "referenceLocator": "pkg:npm/simple@1.0.0" 1661cb0ef41Sopenharmony_ci } 1671cb0ef41Sopenharmony_ci ] 1681cb0ef41Sopenharmony_ci }, 1691cb0ef41Sopenharmony_ci { 1701cb0ef41Sopenharmony_ci "name": "lodash", 1711cb0ef41Sopenharmony_ci "SPDXID": "SPDXRef-Package-lodash-4.17.21", 1721cb0ef41Sopenharmony_ci "versionInfo": "4.17.21", 1731cb0ef41Sopenharmony_ci "packageFileName": "node_modules/lodash", 1741cb0ef41Sopenharmony_ci "description": "Lodash modular utilities.", 1751cb0ef41Sopenharmony_ci "downloadLocation": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 1761cb0ef41Sopenharmony_ci "filesAnalyzed": false, 1771cb0ef41Sopenharmony_ci "homepage": "https://lodash.com/", 1781cb0ef41Sopenharmony_ci "licenseDeclared": "MIT", 1791cb0ef41Sopenharmony_ci "externalRefs": [ 1801cb0ef41Sopenharmony_ci { 1811cb0ef41Sopenharmony_ci "referenceCategory": "PACKAGE-MANAGER", 1821cb0ef41Sopenharmony_ci "referenceType": "purl", 1831cb0ef41Sopenharmony_ci "referenceLocator": "pkg:npm/lodash@4.17.21" 1841cb0ef41Sopenharmony_ci } 1851cb0ef41Sopenharmony_ci ], 1861cb0ef41Sopenharmony_ci "checksums": [ 1871cb0ef41Sopenharmony_ci { 1881cb0ef41Sopenharmony_ci "algorithm": "SHA512", 1891cb0ef41Sopenharmony_ci "checksumValue": "bf690311ee7b95e713ba568322e3533f2dd1cb880b189e99d4edef13592b81764daec43e2c54c61d5c558dc5cfb35ecb85b65519e74026ff17675b6f8f916f4a" 1901cb0ef41Sopenharmony_ci } 1911cb0ef41Sopenharmony_ci ] 1921cb0ef41Sopenharmony_ci } 1931cb0ef41Sopenharmony_ci ], 1941cb0ef41Sopenharmony_ci "relationships": [ 1951cb0ef41Sopenharmony_ci { 1961cb0ef41Sopenharmony_ci "spdxElementId": "SPDXRef-DOCUMENT", 1971cb0ef41Sopenharmony_ci "relatedSpdxElement": "SPDXRef-Package-simple-1.0.0", 1981cb0ef41Sopenharmony_ci "relationshipType": "DESCRIBES" 1991cb0ef41Sopenharmony_ci }, 2001cb0ef41Sopenharmony_ci { 2011cb0ef41Sopenharmony_ci "spdxElementId": "SPDXRef-Package-simple-1.0.0", 2021cb0ef41Sopenharmony_ci "relatedSpdxElement": "SPDXRef-Package-lodash-4.17.21", 2031cb0ef41Sopenharmony_ci "relationshipType": "DEPENDS_ON" 2041cb0ef41Sopenharmony_ci } 2051cb0ef41Sopenharmony_ci ] 2061cb0ef41Sopenharmony_ci} 2071cb0ef41Sopenharmony_ci``` 2081cb0ef41Sopenharmony_ci 2091cb0ef41Sopenharmony_ci### Package lock only mode 2101cb0ef41Sopenharmony_ci 2111cb0ef41Sopenharmony_ciIf package-lock-only is enabled, only the information in the package 2121cb0ef41Sopenharmony_cilock (or shrinkwrap) is loaded. This means that information from the 2131cb0ef41Sopenharmony_cipackage.json files of your dependencies will not be included in the 2141cb0ef41Sopenharmony_ciresult set (e.g. description, homepage, engines). 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ci### Configuration 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ci#### `omit` 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_ci* Default: 'dev' if the `NODE_ENV` environment variable is set to 2211cb0ef41Sopenharmony_ci 'production', otherwise empty. 2221cb0ef41Sopenharmony_ci* Type: "dev", "optional", or "peer" (can be set multiple times) 2231cb0ef41Sopenharmony_ci 2241cb0ef41Sopenharmony_ciDependency types to omit from the installation tree on disk. 2251cb0ef41Sopenharmony_ci 2261cb0ef41Sopenharmony_ciNote that these dependencies _are_ still resolved and added to the 2271cb0ef41Sopenharmony_ci`package-lock.json` or `npm-shrinkwrap.json` file. They are just not 2281cb0ef41Sopenharmony_ciphysically installed on disk. 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ciIf a package type appears in both the `--include` and `--omit` lists, then 2311cb0ef41Sopenharmony_ciit will be included. 2321cb0ef41Sopenharmony_ci 2331cb0ef41Sopenharmony_ciIf the resulting omit list includes `'dev'`, then the `NODE_ENV` environment 2341cb0ef41Sopenharmony_civariable will be set to `'production'` for all lifecycle scripts. 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_ci 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_ci#### `package-lock-only` 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci* Default: false 2411cb0ef41Sopenharmony_ci* Type: Boolean 2421cb0ef41Sopenharmony_ci 2431cb0ef41Sopenharmony_ciIf set to true, the current operation will only use the `package-lock.json`, 2441cb0ef41Sopenharmony_ciignoring `node_modules`. 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_ciFor `update` this means only the `package-lock.json` will be updated, 2471cb0ef41Sopenharmony_ciinstead of checking `node_modules` and downloading dependencies. 2481cb0ef41Sopenharmony_ci 2491cb0ef41Sopenharmony_ciFor `list` this means the output will be based on the tree described by the 2501cb0ef41Sopenharmony_ci`package-lock.json`, rather than the contents of `node_modules`. 2511cb0ef41Sopenharmony_ci 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_ci 2541cb0ef41Sopenharmony_ci#### `sbom-format` 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ci* Default: null 2571cb0ef41Sopenharmony_ci* Type: "cyclonedx" or "spdx" 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ciSBOM format to use when generating SBOMs. 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ci 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ci#### `sbom-type` 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci* Default: "library" 2661cb0ef41Sopenharmony_ci* Type: "library", "application", or "framework" 2671cb0ef41Sopenharmony_ci 2681cb0ef41Sopenharmony_ciThe type of package described by the generated SBOM. For SPDX, this is the 2691cb0ef41Sopenharmony_civalue for the `primaryPackagePurpose` field. For CycloneDX, this is the 2701cb0ef41Sopenharmony_civalue for the `type` field. 2711cb0ef41Sopenharmony_ci 2721cb0ef41Sopenharmony_ci 2731cb0ef41Sopenharmony_ci 2741cb0ef41Sopenharmony_ci#### `workspace` 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ci* Default: 2771cb0ef41Sopenharmony_ci* Type: String (can be set multiple times) 2781cb0ef41Sopenharmony_ci 2791cb0ef41Sopenharmony_ciEnable running a command in the context of the configured workspaces of the 2801cb0ef41Sopenharmony_cicurrent project while filtering by running only the workspaces defined by 2811cb0ef41Sopenharmony_cithis configuration option. 2821cb0ef41Sopenharmony_ci 2831cb0ef41Sopenharmony_ciValid values for the `workspace` config are either: 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_ci* Workspace names 2861cb0ef41Sopenharmony_ci* Path to a workspace directory 2871cb0ef41Sopenharmony_ci* Path to a parent workspace directory (will result in selecting all 2881cb0ef41Sopenharmony_ci workspaces within that folder) 2891cb0ef41Sopenharmony_ci 2901cb0ef41Sopenharmony_ciWhen set for the `npm init` command, this may be set to the folder of a 2911cb0ef41Sopenharmony_ciworkspace which does not yet exist, to create the folder and set it up as a 2921cb0ef41Sopenharmony_cibrand new workspace within the project. 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes. 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_ci#### `workspaces` 2971cb0ef41Sopenharmony_ci 2981cb0ef41Sopenharmony_ci* Default: null 2991cb0ef41Sopenharmony_ci* Type: null or Boolean 3001cb0ef41Sopenharmony_ci 3011cb0ef41Sopenharmony_ciSet to true to run the command in the context of **all** configured 3021cb0ef41Sopenharmony_ciworkspaces. 3031cb0ef41Sopenharmony_ci 3041cb0ef41Sopenharmony_ciExplicitly setting this to false will cause commands like `install` to 3051cb0ef41Sopenharmony_ciignore workspaces altogether. When not set explicitly: 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ci- Commands that operate on the `node_modules` tree (install, update, etc.) 3081cb0ef41Sopenharmony_ciwill link workspaces into the `node_modules` folder. - Commands that do 3091cb0ef41Sopenharmony_ciother things (test, exec, publish, etc.) will operate on the root project, 3101cb0ef41Sopenharmony_ci_unless_ one or more workspaces are specified in the `workspace` config. 3111cb0ef41Sopenharmony_ci 3121cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes. 3131cb0ef41Sopenharmony_ci## See Also 3141cb0ef41Sopenharmony_ci 3151cb0ef41Sopenharmony_ci* [package spec](/using-npm/package-spec) 3161cb0ef41Sopenharmony_ci* [dependency selectors](/using-npm/dependency-selectors) 3171cb0ef41Sopenharmony_ci* [package.json](/configuring-npm/package-json) 3181cb0ef41Sopenharmony_ci* [workspaces](/using-npm/workspaces) 319