Yarn cannot find the release file named in yarnPath
Cannot find module .yarn/releases/yarn-3.x.x.cjsShort 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.
Fix it fast
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/2Match what you see, then jump to its fix
- 1
yarnPath 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
The 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
- 1
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/releases2Fix
Add exceptions to .gitignore so the release folder is tracked, then commit the file.
# .gitignore
.yarn/*
!.yarn/releases
!.yarn/plugins3Verify
The release file is tracked.
git ls-files .yarn/releasesConfirmed by yarnpkg.com
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.yml2Fix
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 install3Verify
Yarn starts and reports its version.
yarn --versionConfirmed by yarnpkg.com
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix