Reputation: 13270
If I use yarn add <package-name>
, Yarn will install both dependencies and devDependencies of <package-name>
.
Is it intended?
I checked the documentation but I couldn't find a way to prevent installing the development dependencies.
devDependencies
are the dependencies that were used to compile the sources of one package, therefore if I am in a production environment I don't need them.
Upvotes: 83
Views: 115954
Reputation: 4475
--production
flag doesn't exist anymore. Use this command instead:
yarn workspaces focus --production
More details here https://yarnpkg.com/cli/workspaces/focus
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.
Upvotes: 107
Reputation: 31
With Yarn 2+, it seems that Yarn focuses on PnP installs, meaning a content-addressable data-structure that replaces classic node_modules
and is assumed to be part of the package, hence package sources will automatically include devDependencies
.
Nevertheless, yarn workspaces focus <name> --production
allows to install a workspace package without `devDependencies. See https://yarnpkg.com/cli/workspaces/focus for more information.
Upvotes: 3
Reputation: 1318
The existing answers seem to miss the point of the question (including the accepted answer).
If I invoke
yarn add <my-package>
, Yarn will install both dependencies and devDependencies of<my-package>
. Is it normal behavior?
No, this sounds like a bug. I don't see this behaviour with the latest version of yarn v1.
If I yarn add foo
to my project, I should then have installed:
foo
foo
and their dependencies recursivelyfoo
If you are running yarn add
it can be assumed you are in a "dev" context.
Upvotes: 2
Reputation: 38207
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
.
Upvotes: 16