Search code examples
yarnpkgnpm-scriptsyarnpkg-v3

command not found: if when running package.json script with Yarn v3 (berry)


I upgraded our projects yarn from v1.22 to v3.1.1. We use workspaces, so I have that plugin. Everything seems fine; other scripts work but when trying to use shell commands I get this error:

> yarn run start
command not found: if
command not found: then
command not found: fi

Here is the script from our package.json:

"scripts": {
    "build": "yarn run --top-level tsc",
    "lint": "yarn run --top-level eslint './src/**/*.{ts,js}'",
    "start": "if [[ $BLAH ]]; then yarn generateEnvFile; fi && yarn copyEnterpriseWsdl && node dist/index.js",
    "generateEnvFile": "node blah.js > .env",
    "copyEnterpriseWsdl": "cp blah blah"
  }

Solution

  • I ended up with more of a workaround than figuring out what the issue was:

    "scripts": {
        // ...
        "start": "/bin/sh ./start-prod.sh"
      }
    

    Where that script has what I really need to run. 🤷‍♂️