Why is yarn installing my devDependencies when I am using YARN_PRODUCTION=true?


When yarn install is run during my build, it is raising an error and failing the build because it is running an install on dependencies and devDependencies. I have already set YARN_PRODUCTION to true.


Yarn isn't installing the devDependencies - it is resolving them in case there is a conflict in the dependency tree. This is a known issue with the yarn project that has an open issue on GitHub: https://github.com/yarnpkg/yarn/issues/3630.

There are 2 possible solutions.

Option 1: Fix the install step.

If the failure is happening because of a missing or misconfigured private dependency, you will need to make it installable. The solution here would be to include a .yarnrc file that will specify the registry url for the scoped package and incorporate the private token. You'll need to do the following:

  1. Create a .yarnrc file at the root of your app directory, add the registry url, and check it into git. The registry url differs from registry to registry (ie. npm vs. gemfury), so check with the documentation of the registry to confirm. The file should look something like this:
"@scope:registry" "https://registry.npmjs.org/:_authToken=${NPM_TOKEN}"
  1. Set the NPM_TOKEN (or the secret token for the registry being used) as an environment variable in Heroku.
heroku config:set NPM_TOKEN=TOKEN_VALUE -a APP_NAME

Option 2: Add the dependency to optionalDependencies.

Adding the dependency to optionalDependencies will display an error, but yarn will continue the installation and not fail the build. These are the yarn docs for that option: https://yarnpkg.com/lang/en/docs/dependency-types/#toc-optionaldependencies.

To do this, add an optionalDependencies key and add the dev dependency in question to it (and remove it from devDependencies.

"optionalDependencies": {
  "package-name": "2.1.2"

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support