npm
Last updated October 25, 2026View source (v0.30.0)
This page explains how Bomly builds a dependency graph for npm projects: the detector chain it runs, what that chain needs, and what it can report.
| Property | Value |
|---|---|
| Package manager | npm |
| Ecosystem | npm |
| Detector chain | npm, syft-detector |
| Evidence patterns | npm-shrinkwrap.json, package-lock.json, package.json |
| Ignored directories | node_modules, dist |
| Multi-module resolution | Yes |
| Install-first support | Yes |
| Remediation hints | direct-bump1, transitive-override2 |
| Commands the chain may run | npm. The Syft fallback is built in; the lite build runs an external syft from PATH instead. |
How npm resolves
The chain is lockfile-first. The npm detector parses package-lock.json directly and produces a full transitive graph with edges, scope (runtime or development), and resolved versions. If you reorder the strategies to prefer the build tool, it runs npm ls instead. The Syft fallback runs only when neither strategy produces a graph.
| Detector | Runs by default | Strategy | Command |
|---|---|---|---|
npm (lockfile strategy) | Yes | Lockfile parser | None |
npm (buildtool strategy) | Fallback | Build tool | npm ls --all --json --package-lock-only |
syft-detector | Final fallback | File recognition | None (Syft is built in) |
The lockfile strategy reads one file and runs nothing, so it never uses the network. The build-tool strategy passes --package-lock-only, so npm reads the lockfile and does not consult node_modules or the registry. See Network and privacy for the shared rule.
Prerequisites
- A committed
package-lock.json. Lockfile format version 2 or higher ("lockfileVersion": 2or3) gives full edge detail. Version 1 lockfiles parse with less detail. - No Node.js installation is required to scan. Bomly parses the lockfile directly.
- For
--install-first:npmonPATH.
Examples
Fix a direct vulnerability
- Bump the affected range in
package.jsonto one that includes the fix. - Re-lock with
npm install. - Re-scan to confirm.
Pin a transitive vulnerability
Use npm overrides (npm 8.3.0 or higher) in package.json:
{
"overrides": {
"lodash": "4.17.21"
}
}
Re-lock and re-scan.
Workspaces
Bomly walks the workspace tree and scans each workspace as a separate subproject. The merged graph shows which workspace introduced each shared dependency:
bomly scan --path ./monorepo
bomly explain lodash --path ./monorepo
--install-first
With --install-first, Bomly runs npm i (the short form of npm install) in the project directory before resolving the graph. That downloads packages from the npm registry and writes to node_modules/. Use it only when the lockfile is missing or stale:
bomly scan --install-first
To append flags to that command, repeat --install-arg. This requires --detectors npm so the arguments target one detector:
# Tolerate peer-dependency conflicts on a legacy project
bomly scan --install-first --detectors npm \
--install-arg --legacy-peer-deps --install-arg --no-audit
Reachability (experimental)
With --analyze, the jsreach analyzer reports an npm package as reachable when app source imports it, directly or through the dependency graph. In a workspace, it follows imports between sibling packages by workspace name. Unreachable is a triage signal, not proof of safety; see Reachability.
Limitations
- Packages added with
npm linkare not in the lockfile, so they are not in the graph. Run a normal install before scanning. - Optional and peer dependencies keep their lockfile flags, but peer-dependency version constraints are not re-checked.
- Subpath imports collapse to the package name for reachability.
import 'lodash/get'andimport 'lodash/fp'both count aslodash. - Lockfile version 1 (npm 5 and 6) parses with less edge detail. Upgrade to npm 7 or higher for full graph data.
Configuration
npm is one detector with two internal strategies, lockfile and buildtool. Its config block controls their order and whether --install-first applies to it:
plugins:
detectors:
npm:
# Reorder or subset the strategies (default: lockfile, buildtool)
strategy: [lockfile, buildtool]
# Set to false to skip this detector when --install-first is passed
installFirst: true
The older detector names npm-detector and npm-native still work as selector aliases of npm.