question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[npm] cache restored but node_modules missing

See original GitHub issue

Hi I’d like to lint my react-based codebase with github actions and use this library to optimize the job duration. My yaml file for workflow configure is here:

name: ESLint
on: [push]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: setup node
        uses: actions/setup-node@v1
        with:
          node-version: "12"

      - name: cache node modules
        id: cache-node_modules
        uses: actions/cache@v1
        env:
          cache-name: cache-node-modules
        with:
          path: ~/.npm
          key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-${{ env.cache-name }}-

      - name: install dependencies
        if: steps.cache-node_modules.outputs.cache-hit != 'true'
        run: npm ci

      - name: run eslint
        run: npm run lint

At first the cache doesn’t hit, npm ci is triggered, this job works and the generated cache is posted to ~/.npm dir.

Post job cleanup. /bin/tar -cz -f /home/runner/work/_temp/885b6838-636b-49ea-a563-41734fd8977d/cache.tgz -C /home/runner/.npm . Cache saved successfully

Next time I run this job, github actions restore cache successfully, as I intended.

Run actions/cache@v1 with: path: ~/.npm key: Linux-cache-node-modules-1001ef79e1a0df9c0bf9013e62376251ae8ec7cb518016d4da61abfc8087539a restore-keys: Linux-cache-node-modules- env: cache-name: cache-node-modules Cache Size: ~46 MB (48000811 B) /bin/tar -xz -f /home/runner/work/_temp/b378e123-f68d-4e18-87d6-7942df1629b7/cache.tgz -C /home/runner/.npm Cache restored from key: Linux-cache-node-modules-1001ef79e1a0df9c0bf9013e62376251ae8ec7cb518016d4da61abfc8087539a

But the step of npm run lint somehow fails.

> Jinrikisha-client@0.1.0 lint /home/runner/work/Jinrikisha-client/Jinrikisha-client > eslint src/**/*.{ts,tsx} sh: 1: eslint: not found …(some npm ERRs) npm WARN Local package.json exists, but node_modules missing, did you mean to install? npm ERR! A complete log of this run can be found in: npm ERR! /home/runner/.npm/_logs/2020-05-10T05_25_36_742Z-debug.log ##[error]Process completed with exit code 1.

I used another cache by changing the key to ${{ runner.os }}-${{ env.cache-name }}-v2-${{ hashFiles('**/package-lock.json') }} and the restore key to ${{ runner.os }}-${{ env.cache-name }}-v2- but the result ends up in the same way.

This may be related to https://github.com/actions/cache/issues/281

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
joshmgrosscommented, Jun 11, 2020

Going to close this issue out.

To summarize: Using restore-keys means you’re not guaranteed to have an exact cache hit and some dependencies could be missing. Using the cache-hit output variable can work for some scenarios, but depending on your ecosystem and the contents of your cache, you may want to run the install step to ensure consistency.

This specific issue was from caching the npm cache, which won’t populate any node_modules.

Thanks all for your feedback and suggestions 😄

3reactions
smorimotocommented, May 11, 2020

Well, you should definitely avoid caching node_modules.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local package.json exists, but node_modules missing
npm start runs a script that the app maker built for easy starting of the app npm install installs all the packages in...
Read more >
Tests failing due to node_modules missing something, but it ...
I tried posting this in the Caching Dependencies section, but I think ... Tests failing due to node_modules missing something, but it works ......
Read more >
Do Not Let NPM Cache Snowball on CI - Gleb Bahmutov
The Cache node_modules shows that it has found the previous cache, restored it, ran NPM CI command, and then saved the new ~/.npm...
Read more >
Caching Dependencies on GitHub Workflows - Rupesh Tiwari
We will use actions/cache@v2 to save and restore npm dependencies. What do we cache?Permalink. Normally we cache node_modules folder in node or ...
Read more >
package-lock.json (missing resolved/integrity) not noticed and ...
To fix the lock file, one currently has to: delete all node_modules directories; delete the package-lock.json file; execute npm install. Expected Behavior.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found