Skip to content

Search

Search the docs, blog, and marketplace.

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.

PropertyValue
Package managernpm
Ecosystemnpm
Detector chainnpm, syft-detector
Evidence patternsnpm-shrinkwrap.json, package-lock.json, package.json
Ignored directoriesnode_modules, dist
Multi-module resolutionYes
Install-first supportYes
Remediation hintsdirect-bump1, transitive-override2
Commands the chain may runnpm. 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.

DetectorRuns by defaultStrategyCommand
npm (lockfile strategy)YesLockfile parserNone
npm (buildtool strategy)FallbackBuild toolnpm ls --all --json --package-lock-only
syft-detectorFinal fallbackFile recognitionNone (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": 2 or 3) 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: npm on PATH.

Examples

Fix a direct vulnerability

  1. Bump the affected range in package.json to one that includes the fix.
  2. Re-lock with npm install.
  3. 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 link are 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' and import 'lodash/fp' both count as lodash.
  • 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.

Footnotes

  1. Update a package declared directly in the project. ↩

  2. Pin an indirect package with the package manager's override feature. ↩