actions/setup-node cannot find a lock file when caching is on
Dependencies lock file is not found in /home/runner/work/my-repo/my-repo. Supported file patterns: package-lock.json,npm-shrinkwrap.json,yarn.lockShort answer
When you set cache on actions/setup-node, it looks for a lock file in the repository root. If the file is not committed, lives in a subfolder, or belongs to a different package manager than the one named in cache, the step fails. Commit the lock file or point cache-dependency-path at it.
Fix it fast
1Find out which cause you have
List the lock files that are committed, and where they sit relative to the repository root.
git ls-files | grep -E '(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml)$'2Match what you see, then jump to its fix
- 1
The lock file exists, but not in the repository rootThe project lives in a subfolder (monorepo)Fix - 2
git ls-files shows no lock file at allThe lock file is not committedFix - 3
cache: npm in the workflow, but the repository has only yarn.lock or pnpm-lock.yamlcache names a different package manager than the project usesFix
- 1
What does the error look like?
Dependencies lock file is not found in /home/runner/work/my-repo/my-repo. Supported file patterns: package-lock.json,npm-shrinkwrap.json,yarn.lockError: Dependencies lock file is not found
Cause 1 of 3
The project lives in a subfolder (monorepo)
1Check
The action searches the repository root by default. A lock file in apps/web is not seen.
git ls-files | grep -E 'lock'2Fix
Point cache-dependency-path at the lock file. It also accepts wildcards and a list.
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: apps/web/package-lock.json3Verify
The setup-node step passes and later reports a cache restore or save.
gh run view --log | grep -i cacheConfirmed by github.com
Cause 2 of 3
The lock file is not committed
1Check
A .gitignore rule or a project that never ran install may keep it out. The action's README strongly recommends committing the lock file.
git check-ignore -v package-lock.json
ls package-lock.json yarn.lock pnpm-lock.yaml2Fix
Generate the lock file locally, remove any ignore rule, and commit it.
npm install
git add package-lock.json
git commit -m "Add lock file"3Verify
The file now appears in the tracked list.
git ls-files package-lock.jsonConfirmed by github.com
Cause 3 of 3
cache names a different package manager than the project uses
1Check
The cache value picks the package manager. The action's default search names package-lock.json, npm-shrinkwrap.json and yarn.lock in the root, and pnpm caching is supported from pnpm 6.10.
grep -n -A4 'setup-node' .github/workflows/*.yml2Fix
Set cache to the manager your lock file belongs to (npm, yarn or pnpm). For pnpm, follow the GitHub example: pnpm/action-setup comes before setup-node, and pnpm caching needs pnpm 6.10.0 or newer.
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm3Verify
The step finds the lock file and the install step runs.
gh run view --log | grep -i -E 'lock|cache'Confirmed by docs.github.com
How do I stop it coming back?
- Commit the lock file and keep it out of .gitignore.
- In a monorepo, always set cache-dependency-path.
- Use the same package manager in the workflow as in local development.
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
Servers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Docker push to Artifact Registry fails from GitHub Actions with a permission error
Permission 'artifactregistry.repositories.uploadArtifacts' denied on resource
The identity your workflow authenticates as lacks the permission artifactregistry.repositories.uploadArtifacts on the target repository.
4 causes, each with a fixServers
Azure App Service on Linux restarts the container and the site never starts
The container restarts again and again and the site returns an application error
App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time.
5 causes, each with a fixServers
bcrypt_lib.node: invalid ELF header inside a Docker container
Error: /app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: invalid ELF header
bcrypt is a compiled addon, so the file in node_modules only runs on the operating system it was installed on.
3 causes, each with a fixServers
AWS CDK cannot find module '@aws-cdk/aws-ec2' (or another @aws-cdk/aws-* package)
Cannot find module '@aws-cdk/aws-ec2'
CDK v2 no longer ships one npm package per service.
3 causes, each with a fixServers
cdk deploy fails in a GitLab job with spawnSync docker ENOENT
code: 'ENOENT'
ENOENT means the operating system found no docker program to run.
3 causes, each with a fix