Issue
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
.
Resolution
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:
- 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}"
- 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"
}