How can I cache npm dependencies in GitHub Actions to speed up CI? #196822
-
🏷️ Discussion TypeQuestion 💬 Feature/Topic AreaCode Search and Navigation BodyI'm using Node.js with GitHub Actions, but every workflow run reinstalls all dependencies from scratch. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can use the built-in cache support from actions/setup-node. Example:
This automatically caches dependencies based on your package-lock.json. If you use Yarn or pnpm, you can change the cache option accordingly. GitHub recommends using dependency caching to reduce workflow execution time and improve CI performance. |
Beta Was this translation helpful? Give feedback.
You can use the built-in cache support from actions/setup-node.
Example:
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
run: npm install
This automatically caches dependencies based on your package-lock.json.
If you use Yarn or pnpm, you can change the cache option accordingly.
GitHub recommends using dependency caching to reduce workflow execution time and improve CI performance.