heroku / heroku/heroku-buildpack-nodejs

Yarn v2 installation error Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

Open
#907 9 comments 8 reactions 0 assignees View on GitHub
bug yarn-2
Dominant language
Shell
Stars
1.3k
Forks
2.6k
Avg merge
1d 13h
Merged PRs (30d)
30

Description

## Describe the bug
Using Yarn v2 workspace (**node_modules linker**, not PnP), the build will fail if `heroku-prebuild` is defined in the root `package.json`

## To Reproduce
Steps to reproduce the behavior:
1. Use Yarn v2 workspace
2. Define a `heroku-prebuild` script in root package.json.
The script could be as simple as:
```json
{
"scripts": {
"heroku-prebuild": "ls"
}
}
```
3. Deploy it (tested with `git push heroku main` or `dpl --provider=heroku`, it doesn't matter)
4. Sufficient to see the error

## Versions (please complete the following information):
- Heroku Stack: `heroku-20`
- Node Version: `14.x`
- NPM or Yarn Version: `2.4.0`
- Buildpack Version: Latest at the time of writing, Not pinned

## Additional context
- If `heroku-prebuild` is not defined, the installation always works.
- `NODE_MODULES_CACHE` has been disabled or enabled, the error persists.
- `NPM_CONFIG_PRODUCTION` and `YARN_PRODUCTION` has been **unset** as per [the official migration guide](https://devcenter.heroku.com/articles/migrating-to-yarn-2#update-heroku-environment-for-node-modules), the error still persists
- No other buildpacks interfering
- No output seen on the log for the `heroku-prebuild` script (suggesting that maybe it wasn't even run)

## Log output (trimmed):
```
-----> Node.js app detected

-----> Creating runtime environment

NPM_CONFIG_LOGLEVEL=error
USE_YARN_CACHE=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=false

-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)

Resolving node version 14.x...
Downloading and installing node 14.16.0...
Using default npm version: 6.14.11
Resolving yarn version 1.22.x...
Downloading and installing yarn (1.22.10)
Using yarn 2.4.0

-----> Restoring cache
Caching has been disabled because NODE_MODULES_CACHE=false

-----> Prebuild
Running heroku-prebuild (yarn)
Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

$ yarn run [--inspect] [--inspect-brk] ...

-----> Build failed

We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
```

Contributor guide

Open the contributing guide

Research direction

Start with the root package.json and reproduce the deployment using a Yarn v2 workspace with the node_modules linker and a heroku-prebuild script. Trace the buildpack's Prebuild entry point and compare the behavior with the script removed. Done means heroku-prebuild runs successfully without the node_modules state file error.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.