reactjsnode.jsyarnpkgyarnpkg-v4

Yarn build fails with permission denied: . after upgrading from Yarn 1 to Yarn 4


I'm working on a React components package. After upgrading my project from Yarn 1 to Yarn 4, my yarn build command started failing with the error:

permission denied: .

Here's the relevant script from my package.json:

"scripts": {
  "build": ". ./build.sh"
}

This used to work fine with Yarn 1. After the upgrade, I get the error both locally and in CI.


Solution

  • The issue stems from how Yarn 4 handles script execution differently than Yarn 1.

    You're using the . (dot) command, which is shorthand for source in POSIX shells. This command attempts to run the script in the current shell process rather than spawning a new one.

    Yarn 1 used bash or the user's default shell (depending on environment), which typically allowed . to execute scripts, assuming appropriate permissions and environment setup.

    However, Yarn 4 introduces stricter and more predictable shell execution.

    Change the script to invoke explicitly sh:

    "build": "sh ./build.sh"