2019-10-18 18:40:47 +02:00
# No Cache Detected
2020-04-03 09:51:46 +02:00
### Why This Error Occurred
2019-10-18 18:40:47 +02:00
A Next.js build was triggered in a continuous integration environment, but no cache was detected.
This results in slower builds and can hurt Next.js' persistent caching of client-side bundles across builds.
2020-04-03 09:51:46 +02:00
### Possible Ways to Fix It
2019-10-18 18:40:47 +02:00
> **Note**: If this is a new project, or being built for the first time in your CI, you can ignore this error.
> However, you'll want to make sure it doesn't continue to happen and fix it if it does!
Configure Next.js' cache to be persisted across builds. Next.js stores its cache in the `.next/cache` directory.
Storing this folder across builds varies by CI provider. We've provided a list of a few common providers below.
2020-04-21 11:47:12 +02:00
#### Vercel
2019-10-18 18:40:47 +02:00
Next.js caching is automatically configured for you. There's no action required on your part.
2020-04-03 09:51:46 +02:00
#### CircleCI
2019-10-18 18:40:47 +02:00
Edit your `save_cache` step in `.circleci/config.yml` to include `.next/cache` :
```yaml
steps:
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- ./.next/cache
```
If you do not have a `save_cache` key, please follow CircleCI's [documentation on setting up build caching ](https://circleci.com/docs/2.0/caching/ ).
2020-04-03 09:51:46 +02:00
#### Travis CI
2019-10-18 18:40:47 +02:00
Add or merge the following into your `.travis.yml` :
```yaml
cache:
directories:
- $HOME/.cache/yarn
- node_modules
- .next/cache
```
2020-04-03 09:51:46 +02:00
#### GitLab CI
2019-10-18 18:40:47 +02:00
Add or merge the following into your `.gitlab-ci.yml` :
```yaml
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
- .next/cache/
```
2020-04-03 09:51:46 +02:00
#### Netlify CI
2019-10-18 18:40:47 +02:00
2020-05-27 22:30:39 +02:00
Use [Netlify Plugins ](https://www.netlify.com/products/build/plugins/ ) with [`netlify-plugin-cache-nextjs` ](https://www.npmjs.com/package/netlify-plugin-cache-nextjs ).
2019-10-18 18:40:47 +02:00
2020-04-03 09:51:46 +02:00
#### AWS CodeBuild
2019-10-18 18:40:47 +02:00
Add (or merge in) the following to your `buildspec.yml` :
```yaml
cache:
paths:
- 'node_modules/**/*' # Cache `node_modules` for faster `yarn` or `npm i`
- '.next/cache/**/*' # Cache Next.js for faster application rebuilds
```
2020-01-23 11:18:00 +01:00
2020-04-03 09:51:46 +02:00
#### GitHub Actions
2020-01-23 21:40:02 +01:00
Using GitHub's [actions/cache ](https://github.com/actions/cache ), add the following step in your workflow file:
```yaml
2020-07-23 06:06:50 +02:00
uses: actions/cache@v2
2020-01-23 21:40:02 +01:00
with:
path: ${{ github.workspace }}/.next/cache
2021-07-22 05:12:39 +02:00
# Generate a new cache whenever packages or source files change.
2021-10-19 00:19:22 +02:00
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
2021-07-22 05:12:39 +02:00
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
2020-01-23 21:40:02 +01:00
```
2020-04-03 09:51:46 +02:00
#### Bitbucket Pipelines
2020-01-23 11:18:00 +01:00
Add or merge the following into your `bitbucket-pipelines.yml` at the top level (same level as `pipelines` ):
```yaml
definitions:
caches:
nextcache: .next/cache
```
2020-01-23 14:30:18 +01:00
Then reference it in the `caches` section of your pipeline's `step` :
2020-01-23 11:18:00 +01:00
2020-01-23 14:30:18 +01:00
```yaml
2020-01-23 11:18:00 +01:00
- step:
name: your_step_name
caches:
- node
- nextcache
```
2020-04-20 10:09:38 +02:00
#### Heroku
Using Heroku's [custom cache ](https://devcenter.heroku.com/articles/nodejs-support#custom-caching ), add a `cacheDirectories` array in your top-level package.json:
```javascript
"cacheDirectories": [".next/cache"]
```
2021-03-03 10:47:19 +01:00
#### Azure Pipelines
Using Azure Pipelines' [Cache task ](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/cache ), add the following task to your pipeline yaml file somewhere prior to the task that executes `next build` :
```yaml
- task: Cache@2
displayName: 'Cache .next/cache'
inputs:
key: next | $(Agent.OS) | yarn.lock
path: '$(System.DefaultWorkingDirectory)/.next/cache'
```