/flags/yarn/yarn-install-production
yarn install --production: skip devDependencies (Yarn 1 and Yarn 4)
- tool
- Yarn
- command
- yarn install
- flag
- --production[=true|false]
- default
- false (true in Yarn 1 when NODE_ENV=production)
yarn install --production installs only dependencies and skips devDependencies, the Yarn 1 (Classic) way to build a lean node_modules for a server or a Docker image. Yarn 1 also switches to it automatically when NODE_ENV=production; --production=false forces the full install. Yarn 2 and later do not have the flag: there, yarn workspaces focus --production does the same job.
Yarn 1: with and without the flag
cat > package.json <<'EOF'
{
"name": "demo",
"version": "1.0.0",
"license": "MIT",
"dependencies": { "is-number": "7.0.0" },
"devDependencies": { "is-odd": "3.0.1" }
}
EOF
npx --yes yarn@1 install --silent >/dev/null 2>&1
echo "--- yarn install"
ls node_modules
rm -rf node_modules
npx --yes yarn@1 install --production --frozen-lockfile --silent >/dev/null 2>&1
echo "--- yarn install --production --frozen-lockfile"
ls node_modules
rm -rf node_modules
NODE_ENV=production npx --yes yarn@1 install --frozen-lockfile --silent >/dev/null 2>&1
echo "--- NODE_ENV=production"
ls node_modulesOutput
--- yarn install is-number is-odd --- yarn install --production --frozen-lockfile is-number --- NODE_ENV=production is-number
The dev dependency is-odd is installed only by the plain yarn install. The lockfile written by the first run is reused unchanged by the frozen installs.
Yarn 1 and Yarn 4 equivalents
| Goal | Yarn 1 (Classic) | Yarn 2 – 4 (Berry) |
|---|---|---|
| Skip devDependencies | yarn install --production | yarn workspaces focus --production |
| Production deps of every workspace | yarn install --production (at the root) | yarn workspaces focus --all --production |
| Fail if the lockfile would change | --frozen-lockfile | --immutable |
| Force dev deps under NODE_ENV=production | --production=false | not needed (NODE_ENV is ignored) |
| Make it the default | production true in .yarnrc | - |
yarn workspaces focus is part of Yarn 4 itself; in Yarn 2 and 3 it comes from the workspace-tools plugin (yarn plugin import workspace-tools). The full Classic versus Berry comparison is in Yarn classic vs Yarn Berry.
Dockerfile (Yarn 1)
FROM node:24-slim
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production --frozen-lockfile && yarn cache clean
COPY . .
CMD ["node", "server.js"]yarn cache clean keeps the global cache out of the image layer.
Pitfalls
- When the image also builds the app, install everything first, build, then reinstall with
--productionin a new stage; build tools such as TypeScript live indevDependencies. - A runtime dependency listed under
devDependenciesonly fails in production, asCannot find module. Move it withyarn add pkg. NODE_ENV=productionexported for the whole CI job makes Yarn 1 skip test tools; tests then fail to start. Set it only for the production install.yarn install --productionwith Yarn 4 is an unknown option error, not a silent no-op; checkyarn --versionwhen copying old scripts.
npm and pnpm call the same idea npm install --omit=dev and pnpm install --prod: see npm install --omit=dev and pnpm install --prod.
FAQ
Why does yarn install --production not work in Yarn 4?
Yarn 2 and later removed the flag. Use yarn workspaces focus --production (built into Yarn 4; a plugin in Yarn 2 and 3) to install only the production dependencies of the current workspace.
Does NODE_ENV=production change yarn install in Yarn 1?
Yes. With NODE_ENV=production, Yarn 1 skips devDependencies as if --production were passed. Use --production=false in a build step that needs dev tools under that environment.
Does --production change yarn.lock?
No. yarn.lock always lists every dependency; the flag only decides what is installed into node_modules.