Skip to content
Latchkey

npm install: Usage, Options & Common CI Errors

Install dependencies from package.json - and survive it in CI.

npm install reads package.json, resolves the dependency tree, writes node_modules, and updates package-lock.json. In CI it is the slow, flaky step - here is what it does and how to keep it green.

What it does

Resolves every dependency (and peer/optional deps) into a tree, fetches tarballs from the registry, writes node_modules, and creates or updates package-lock.json. Runs lifecycle scripts (preinstall, install, postinstall) unless --ignore-scripts is set.

Common usage

Terminal
npm install                 # install all deps from package.json
npm install lodash          # add a runtime dependency
npm install -D typescript   # add a dev dependency
npm install --ignore-scripts        # skip pre/post install scripts
npm install --no-save react         # install without writing package.json

Common CI error: ERESOLVE peer conflict

CI fails with "npm error code ERESOLVE / could not resolve dependency tree" because a package demands a peer version another package will not satisfy. Reproduce locally, then pin the offending versions in package.json. As a last resort use --legacy-peer-deps to fall back to npm 6 resolution; prefer --legacy-peer-deps over --force, which can install a broken tree.

Terminal
# fix the real conflict, or unblock CI explicitly:
npm install --legacy-peer-deps

Key options

FlagEffect
-D, --save-devAdd to devDependencies
--no-saveDo not modify package.json
--ignore-scriptsSkip lifecycle scripts
--legacy-peer-depsIgnore peer dep conflicts (npm 6 behavior)
--omit=devSkip devDependencies

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →