Files
next.js/errors/next-dynamic-api-wrong-context.mdx
T
74a19b7467 docs: unify the header deps by removing # (#72391)
## 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]>
2024-11-07 08:58:43 +00:00

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)