setup-node: Npm dependency cache never gets created

Description:

When caching npm dependencies, initial cache never gets created.

Action version:

v3

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

Run actions/setup-node@v3 Attempting to download 20.4.0… Acquiring 20.4.0 - x64

Repro steps:

I have setup-node configured with npm cache:

      - name: Setup NodeJS
        uses: actions/setup-node@v3
        with:
          node-version: ${{ env.nodejs_version }}
          cache: 'npm'
          cache-dependency-path: ${{ env.repo_dir }}/package-lock.json

      - name: Install NodeJS modules
        run: | 
          cd $repo_dir && npm ci

When workflow runs, setup-node sees there is no cache:

Run actions/setup-node@v3
Attempting to download 20.4.0...
Acquiring 20.4.0 - x64 from https://github.com/actions/node-versions/releases/download/20.4.0-5484146983/node-20.4.0-linux-x64.tar.gz
Extracting ...
/usr/bin/tar xz --strip 1 --warning=no-unknown-keyword -C /home/runner/work/_temp/48b89860-06fe-4719-88d8-9b348eae167b -f /home/runner/work/_temp/9cc686a7-e143-4ead-85e4-ecfcab256528
Adding to the cache ...
Environment details
/opt/hostedtoolcache/node/20.4.0/x64/bin/npm config get cache
/home/runner/.npm
npm cache is not found

Install of packages completes:

Run cd $repo_dir && npm ci
(node:1860) [DEP0170] DeprecationWarning: The URL git+ssh://git@github.com-id_rsa_file:mjgs/file#7c95d46d827416d4dd377e14fbeda5430cec26cc is invalid. Future versions of Node.js will throw an error.
(Use `node --trace-deprecation ...` to show where the warning was created)
added 205 packages, and audited 206 packages in 3m

However looking at Actions page Caches tab afterwards, no cache got created. Same thing happens on re-running the workflow.

56921DA6-D87F-4EE7-981E-2F1C065A7C36

Expected behavior:

I expected a cache entry to get created on Actions page Caches tab, and for that to get restored on subsequent runs.

Actual behavior:

No cache ever gets created. How do I create the initial cache?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@dusan-trickovic I figured out why old code was being installed. Npm was installing from package-lock.json.

I updated install command to:

cd $repo_dir && npm install --no-package-lock

You have to specifically tell npm to not use the lock file. You might consider mentioning this gotcha in your docs or on stdout.

So now I am back to my original issue:

Why isn’t the cache speeding up installs?

Shouldn’t the install take seconds since it’s using the npm cache which is restored by the setup-node cache feature?

Thanks for your comments, only just seen them now. I ended up getting this working using the following step:

      - name: Cache NodeJS dependencies
        if: ${{ env.cache_enabled == 'yes' }}
        id: cache
        uses: actions/cache@v3
        with:
          path: ${{ env.repo_dir }}/node_modules
          key: modules-${{ hashFiles('repo/package-lock.json') }}