Why will yarn install dev dependencies when I just need the builds?
Solution 1
Use --production=true
(or simply --production
or --prod
for short). It is indeed normal behaviour; Yarn assumes you are in a 'development' context unless your NODE_ENV environment variable is set to 'production'.
Have a look at Yarn's documentation.
Solution 2
As said in the comment by @ddotsenko
Not "broken" but "badly designed" --prod still downloads and "installs" dev packages IF yarn needs to resolve "full tree". Just use
yarn install --production --frozen-lockfile
and matching yarn.lock and --production will work as expected.
That worked to remove a 210 MB node_modules to 70 MB, similar to npm
and pnpm
.
Solution 3
NODE_ENV=production
also prevent install devDependencies
Solution 4
Yarn has a --production option, which will cause it to install only production dependencies. This is shown here
Related videos on Youtube
Comments
-
vdegenne almost 2 years
If I invoke
yarn add <my-package>
, Yarn will install both dependencies and devDependencies of<my-package>
. Is it normal behavior ?I checked the documentation but I couldn't find a way to prevent it from installing the development dependencies (which I don't need). I believe devDependencies are the dependencies that were used to compile the sources into the build scripts. And building my app I just need the builds.
-
brodybits almost 5 yearsThis functionality seems to be broken due to github.com/yarnpkg/yarn/issues/6323
-
ddotsenko almost 4 yearsNot "broken" but "badly designed"
--prod
still downloads and "installs"dev
packages IF yarn needs to resolve "full tree". Just useyarn install --production --frozen-lockfile
and matchingyarn.lock
and--production
will work as expected. -
serv-inc over 3 years@ddotsenko : that is so helpful, it is now an answer . Please write your own for your well-deserved credit and @ notify me for mine to be deleted.
-
akshat about 3 years
--production
flag has been deprecated for yarn 2.0. How to prevent yarn 2.0 from installing dev dependencies? -
zyfyy over 2 yearsuse
NODE_ENV=production
as environments before excuteyarn
oryarn install
-
tomdaly over 2 yearsLate to the party but the new way to do this in Yarn 2+ is by using
yarn workspaces focus --production --all
: yarnpkg.com/cli/workspaces/focus -
Resisty over 2 yearsUnfortunately I don't have an answer, but I'd like to note that none of the above is correct as of January 2022. Yarn will always install devDependencies regardless of options and NODE_ENV envvar.