Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*bug* Yarn will not install devDependencies when NODE_ENV=production #2739

Closed
mldangelo opened this issue Feb 21, 2017 · 17 comments
Closed

*bug* Yarn will not install devDependencies when NODE_ENV=production #2739

mldangelo opened this issue Feb 21, 2017 · 17 comments

Comments

@mldangelo
Copy link

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
@LINKIWI
Copy link

LINKIWI commented Feb 22, 2017

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?

@mldangelo
Copy link
Author

@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.

@DavidBadura
Copy link

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

@mnpenner
Copy link

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.

@rarkins
Copy link
Contributor

rarkins commented Jul 24, 2017

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 npm@5.3.0 is not.

@antoinerousseau
Copy link

@rally25rs
Copy link
Contributor

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.

@sir-gon
Copy link

sir-gon commented Jun 7, 2018

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.

@cweekly
Copy link

cweekly commented Jun 12, 2018

@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".

@SalathielGenese
Copy link

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

@aemc
Copy link

aemc commented Mar 18, 2019

Thank goodness for this thread.

@mrdulin
Copy link

mrdulin commented Mar 21, 2019

Same issue. Good to know. Thanks.

@dazlious
Copy link

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

@batica81
Copy link

This was a very difficult issue to track down, thank you for this thread!

@rdimascio
Copy link

6 years later and this thread is still saving jobs.

@Dema1348
Copy link

Dema1348 commented Mar 9, 2023

6 years later and this thread is still saving jobs.

It´s true, this thread saved my life

@mirupal
Copy link

mirupal commented Oct 30, 2023

saved me too. But still 1-2 hours lost to debugging :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests