Skip to content

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

@jasonlimantoro

Description

@jasonlimantoro

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:
    {
        "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, 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] <scriptName> ...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions