Search code examples
gatsbyyarnpkgnetlify

yarn: command not found after gatsby deployment to netlify


I keep getting this error.

Executing user command: yarn build
/usr/local/bin/build: line 112: yarn: command not found

I read from Netlify - Manage build dependencies that yarn must be included in my package.json. Yet I see yarn mentioned in my package.json

I've cleaned the cached and deployed again. I tried adding yarn and npm version as a build environment but it still doesn't work. I also looked into How to change your default package manager for your next project? but didn't find a json with the following structure:

{
  "cli": {
    "packageManager": "yarn"
  }
}

FWIW this builds fine locally. It only errors after I push to my remote repo and Netlify is building. What makes this even more weird is that this error doesn't happen if I use the default starter.


Solution

  • It's a bit counter intuitive, but all I needed to do was add an empty yarn.lock file to the root directory and push it to my repo. The error message went away immediately!

    From Netlify - Manage build dependencies

    ⚠️ yarn needs a yarn.lock

    If any of your build scripts start with yarn, you must have a yarn.lock file.

    Netlify's buildbot will not install Yarn without it.