mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## Summary Remove redundant `#` from [error pages](https://github.com/vercel/next.js/tree/canary/errors). ## Description Follow up #52038 and #72263. Updated [template.txt](https://github.com/vercel/next.js/blob/canary/errors/template.txt) and clarified the header deps. Then rewrite as per the template. ### Improving Documentation - [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide Co-authored-by: Delba de Oliveira <[email protected]>
44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
---
|
|
title: Dynamic API was called outside request
|
|
---
|
|
|
|
## Why This Error Occurred
|
|
|
|
A Dynamic API was called outside a request scope. (Eg.: Global scope).
|
|
|
|
Note that Dynamic APIs could have been called deep inside other modules/functions (eg.: third-party libraries) that are not immediately visible.
|
|
|
|
## Possible Ways to Fix It
|
|
|
|
Make sure that all Dynamic API calls happen in a request scope.
|
|
|
|
Example:
|
|
|
|
```jsx filename="app/page.js"
|
|
import { cookies } from 'next/headers'
|
|
|
|
- const cookieStore = cookies()
|
|
export default function Page() {
|
|
+ const cookieStore = cookies()
|
|
return ...
|
|
}
|
|
```
|
|
|
|
```jsx filename="app/foo/route.js"
|
|
import { headers } from 'next/headers'
|
|
|
|
- const headersList = headers()
|
|
export async function GET() {
|
|
+ const headersList = headers()
|
|
return ...
|
|
}
|
|
```
|
|
|
|
## Useful Links
|
|
|
|
- [`headers()` function](https://nextjs.org/docs/app/api-reference/functions/headers)
|
|
- [`cookies()` function](https://nextjs.org/docs/app/api-reference/functions/cookies)
|
|
- [`draftMode()` function](https://nextjs.org/docs/app/api-reference/functions/draft-mode)
|
|
- [`unstable_noStore()` function](https://nextjs.org/docs/app/api-reference/functions/unstable_nostore)
|
|
- [`unstable_cache()` function](https://nextjs.org/docs/app/api-reference/functions/unstable_cache)
|