Yarn: *bug* Yarn will not install devDependencies when NODE_ENV=production

12

Current behavior
Currently, when NODE_ENV=production, yarn will only install dependencies and not devDependencies. This behavior mirrors npm, but isn't reflected anywhere in yarn's documentation. and there's no flag to force yarn to all dependencies. The ability to force all dependencies to be installed is useful to me for ci testing. My current workaround is to use NODE_ENV=development yarn.

Proposed solutions

  1. Add a flag which forces all dependencies to be installed yarn install --all (?)
  2. Update the documentation to reflect this shortcoming.

I'm happy to do either or both if pull requests are welcome.

node.js, yarn and operating system version.

  • node v7.5.0
  • yarn v0.20.3
  • Mac OS and Ubuntu 14.04
mldangelo picture mldangelo  ·  21 Feb 2017

Most helpful comment

118

@mldangelo You can install the dev dependencies in NODE_ENV=production with yarn install --production=false

DavidBadura picture DavidBadura  ·  23 Feb 2017

All comments

23

I don't think this is a bug. As you mentioned, npm has exactly the same behavior when you set NODE_ENV=production. I don't see why NODE_ENV=production should not only install production dependencies.

As a side note: if you rely on packages from devDependencies in a production environment, it sounds like these shouldn't be dev dependencies at all?

LINKIWI picture LINKIWI  ·  22 Feb 2017
0

@LINKIWI I've got weird ci configurations that probably need to be refactored. Here's one of them where I run tests (which rely on dev dependencies) with my application in production mode.

Would either of my suggestions be welcome? Or if this is something that you believe only I experience, I'll happily close the issue.

mldangelo picture mldangelo  ·  22 Feb 2017
118

@mldangelo You can install the dev dependencies in NODE_ENV=production with yarn install --production=false

DavidBadura picture DavidBadura  ·  23 Feb 2017
3

Good to know about --production=false. I think that should be documented too.

I needed this feature too for CI because I need all the packages to build my project, but webpack (and the react library in particular) should have NODE_ENV=production to create a smaller bundle. After the bundle is built, I actually don't need any node_modules at all in production.

mnpenner picture mnpenner  ·  30 Apr 2017
7

FYI, I seem to have experienced the opposite behaviour in yarn 0.27.5. When NODE_ENV=production is set, yarn is still installing devDependencies, while [email protected] is not.

rarkins picture rarkins  ·  24 Jul 2017
0
antoinerousseau picture antoinerousseau  ·  22 Aug 2017
6

As mentioned in other comments, this is the intended behavior. The documentation for the --production=false flag to override it is here: https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-production

yarn install --production[=true|false]
Yarn will not install any package listed in devDependencies if the NODE_ENV environment variable is set to production. Use this flag to instruct Yarn to ignore NODE_ENV and take its production-or-not status from this flag instead.

I'm going to mark this issue 'closed' for now, but if you feel there is more to it that needs resolved, let us know and we can re-open it.

rally25rs picture rally25rs  ·  22 Aug 2017
18

I'm using NODE_ENV=production to produce a "production" build in a CI/CD (docker) environment, so... I need devDependencies installed to produce the build.
I think, this npm/yarn behavior is not clear at all.

sir-gon picture sir-gon  ·  7 Jun 2018
1

@sir-gon I'm about to help a colleague resolve this same situation. I think I grok the yarn docs cited above; all that should be required is to do NODE_ENV=production yarn install --production=false, so node/webpack/etc do their thing for production, but yarn installs everything including devDependencies.

Tangent: seems to me with both yarn and npm there's insufficient distinction between "dependencies needed to build the software" and "dependencies needed at runtime".

cweekly picture cweekly  ·  12 Jun 2018
0

I faced the same issue and thank for you explanations. Here is how I circumvent this under Docker environment https://stackoverflow.com/questions/31889867/docker-compose-not-overriding-dockerfile-environment-variables#answer-53705415

SalathielGenese picture SalathielGenese  ·  10 Dec 2018
0

Thank goodness for this thread.

aemc picture aemc  ·  18 Mar 2019
0

Same issue. Good to know. Thanks.

mrdulin picture mrdulin  ·  21 Mar 2019
0

Thx for this thread! Ran into this issue with docker and it was not very obvious as I migrated from one dockerfile and had quite a lot changed

dazlious picture dazlious  ·  17 Mar 2020