Yarn: `yarn` skips dev dependencies if NODE_ENV is set to "production"

Created on 15 Nov 2016  路  6Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
calling yarn now skips dev dependencies

If the current behavior is a bug, please provide the steps to reproduce.

$ NODE_ENV=production yarn ls | grep mocha # nothing
$ NODE_ENV=development yarn ls | grep mocha # correct behavior

What is the expected behavior?
previous versions of yarn used to install all dependencies even with NODE_ENV=production. The documentation also explains the use of --production which makes this a little bit counterintuitive.

Please mention your node.js, yarn and operating system version.

  • yarn 0.17.0
  • node v6.9.1
  • os debian:jessie running on docker

Most helpful comment

$ NODE_ENV=development yarn install

will do the equivalent of what you want. Subsequent shell commands will have the previous value of NODE_ENV too.

All 6 comments

The behavior you've outlined matches the docs.

yarn install --production

Using the --production flag, or when the NODE_ENV environment variable is set to production, Yarn will not install any package listed in devDependencies

@allcentury I see, you are indeed correct, I just missed that part. What threw me off is the difference between 0.16.0 and 0.17.0.

How do I install my dev packages then ?

If you need your dev packages in production promote them to the dependencies group.

@allcentury that sounds like a workaround. I want to install my deps with the production flag on and then run the test suite.

Ideally I would build my container with NODE_ENV=production and then docker run yarn --dev && ./test.sh or something similar.

$ NODE_ENV=development yarn install

will do the equivalent of what you want. Subsequent shell commands will have the previous value of NODE_ENV too.

If anyone is interested you can also use .yarnrc to override this behaviour. I did this to fix my heroku builds without having to force NODE_ENV to development

--install.production false
Was this page helpful?
0 / 5 - 0 ratings