Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

actions/setup-node cannot find a lock file when caching is on

ErrorDependencies lock file is not found in /home/runner/work/my-repo/my-repo. Supported file patterns: package-lock.json,npm-shrinkwrap.json,yarn.lock

Short 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.

  • Applies to GitHub Actions, actions/setup-node v4, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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)$'
  2. 2Match what you see, then jump to its fix

    1. 1The lock file exists, but not in the repository rootThe project lives in a subfolder (monorepo)Fix
    2. 2git ls-files shows no lock file at allThe lock file is not committedFix
    3. 3cache: npm in the workflow, but the repository has only yarn.lock or pnpm-lock.yamlcache names a different package manager than the project usesFix

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.lock
  • Error: 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.json

3Verify

The setup-node step passes and later reports a cache restore or save.

gh run view --log | grep -i cache

Confirmed by github.com

Did this fix it?

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.yaml

2Fix

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.json

Confirmed by github.com

Did this fix it?

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/*.yml

2Fix

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: pnpm

3Verify

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

Did this fix it?

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

Next step

Want this handled for good?

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