Install npm dependencies without devDependencies
Use npm omit settings for runtime installs, retain the lockfile, and keep build-time tools available in the build stage.
Use --omit=dev to leave development dependencies out of the installed tree:
npm install --omit=dev
For a deployment with a committed, consistent lockfile, prefer:
npm ci --omit=dev
npm 7 introduced the omit setting. The older --production option maps to omitting development dependencies. This does not mean that npm installs only entries from the root dependencies object: required transitive dependencies, optional dependencies, and applicable peer dependencies can still be installed.
Understand environment defaults
When NODE_ENV is production, npm's default omit list includes dev:
# POSIX shell
NODE_ENV=production npm install
$env:NODE_ENV = 'production'
npm install
Explicit npm settings can override defaults. For example, --include=dev takes precedence over omitting that dependency type. When the effective omit list includes dev, npm sets NODE_ENV=production for lifecycle scripts. Separately, setting this variable for your application may change framework behavior.
Omitted dependencies are still resolved and represented in the lockfile; omission controls installation on disk. Do not remove them from the lockfile by hand.
Separate build and runtime requirements
A runtime-stage Dockerfile can include this fragment after establishing its working directory:
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
Build tools such as TypeScript, bundlers, and test runners belong in the stage that needs them. Install development dependencies for that stage, perform the build, and transfer the required output into the runtime stage. A production install may still execute lifecycle scripts, so check whether those scripts need build tools or generated files.
If production reports a missing module, confirm that code executed at runtime declares the module as a runtime dependency. Also inspect optional dependencies, platform differences, build output, and copied files; a misplaced development dependency is only one possible cause.
Optional and global packages
To omit optional dependencies as well:
npm ci --omit=dev --omit=optional
npm ls --omit=dev --depth=0
Only omit optional packages after testing the fallback behavior. Some applications depend on the capability an optional package provides in a particular environment.
A global install is not a way to install a project's development toolchain. Published packages' development dependencies are not installed as consumer dependencies; use a local project install for its build and test requirements.
References
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan