rsnext/errors/no-cache.md
Chris Patterson 74a65332a4
Changing GitHub Actions cache documentation (#28228)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-06 19:01:38 +00:00

132 lines
3.7 KiB
Markdown

# No Cache Detected
### Why This Error Occurred
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.
### Possible Ways to Fix It
> **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.
#### Vercel
Next.js caching is automatically configured for you. There's no action required on your part.
#### CircleCI
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/).
#### Travis CI
Add or merge the following into your `.travis.yml`:
```yaml
cache:
directories:
- $HOME/.cache/yarn
- node_modules
- .next/cache
```
#### GitLab CI
Add or merge the following into your `.gitlab-ci.yml`:
```yaml
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
- .next/cache/
```
#### Netlify CI
Use [Netlify Plugins](https://www.netlify.com/products/build/plugins/) with [`@netlify/plugin-nextjs`](https://www.npmjs.com/package/@netlify/plugin-nextjs).
#### AWS CodeBuild
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
```
#### GitHub Actions
Using GitHub's [actions/cache](https://github.com/actions/cache), add the following step in your workflow file:
```yaml
uses: actions/cache@v2
with:
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
```
#### Bitbucket Pipelines
Add or merge the following into your `bitbucket-pipelines.yml` at the top level (same level as `pipelines`):
```yaml
definitions:
caches:
nextcache: .next/cache
```
Then reference it in the `caches` section of your pipeline's `step`:
```yaml
- step:
name: your_step_name
caches:
- node
- nextcache
```
#### 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"]
```
#### 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'
```