Why will yarn install dev dependencies when I just need the builds?
Javascriptnode.jsNpmYarnpkgJavascript Problem Overview
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.
Javascript Solutions
Solution 1 - Javascript
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 - Javascript
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 - Javascript
NODE_ENV=production
also prevent install devDependencies
Solution 4 - Javascript
Yarn has a --production option, which will cause it to install only production dependencies. This is shown here