Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Yarn cannot find the release file named in yarnPath

ErrorCannot find module .yarn/releases/yarn-3.x.x.cjs

Short answer

Yarn 2 and newer can run a copy of itself stored in the project, named by yarnPath in .yarnrc.yml. If that file is not on disk, Yarn fails with Cannot find module. Restore .yarn/releases from git, stop ignoring it, or pin the version again with yarn set version.

  • Applies to Yarn 3, Yarn 4, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the yarnPath setting and check whether the file it names exists.

    grep -n "yarnPath" .yarnrc.yml
    ls -l .yarn/releases/
  2. 2Match what you see, then jump to its fix

    1. 1yarnPath names a file under .yarn/releases and that folder is empty or missing after a clone, a CI checkout or a Docker COPYThe release file was never committed, or is gitignoredFix
    2. 2The path in yarnPath is correct but the file is absent, for example after cleaning the folderThe file was deleted or never existed on this machine, and yarnPath still points to itFix

What does the error look like?

  • Cannot find module .yarn/releases/yarn-3.x.x.cjs

Cause 1 of 2

The release file was never committed, or is gitignored

1Check

The Yarn documentation says .yarn/releases belongs in version control, while .yarn/cache and .pnp.* may be ignored. A blanket .yarn/* ignore rule without exceptions drops the release.

git check-ignore -v .yarn/releases/*
git ls-files .yarn/releases

2Fix

Add exceptions to .gitignore so the release folder is tracked, then commit the file.

# .gitignore
.yarn/*
!.yarn/releases
!.yarn/plugins

3Verify

The release file is tracked.

git ls-files .yarn/releases

Confirmed by yarnpkg.com

Did this fix it?

Cause 2 of 2

The file was deleted or never existed on this machine, and yarnPath still points to it

1Check

yarnPath is the path of a Yarn binary used instead of the global one, for every command run inside the folder that the rc file covers.

cat .yarnrc.yml

2Fix

Run yarn set version to download a release into the project and write the setting again. The docs describe the downloaded release being stored inside the project and referenced through yarnPath when needed.

yarn set version stable
yarn install

3Verify

Yarn starts and reports its version.

yarn --version

Confirmed by yarnpkg.com

Did this fix it?

How do I stop it coming back?

  • Commit .yarn/releases and .yarnrc.yml with the project, as the Yarn guide advises.
  • Check the CI checkout and any Docker COPY step include the .yarn folder.
  • After changing the Yarn version, commit the new release file in the same change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.