/
githubmirror
/
next.js
Обзор
Документация
Войти
/
githubmirror
/
next.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v15.5.22
errors/next-dynamic-api-wrong-context.mdx
43 строки
1 KB
LioRael
docs: add await before headers() and cookies() calls (#73315)
28 ноя 2024, 17:19
Не верифицирован
28 ноя 2024, 17:19
f8fddfa
Код
Авторство
О чём код?
--- 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: ```diff filename="app/page.js" import { cookies } from 'next/headers' - const cookieStore = await cookies() export default async function Page() { + const cookieStore = await cookies() return ... } ``` ```diff filename="app/foo/route.js" import { headers } from 'next/headers' - const headersList = await headers() export async function GET() { + const headersList = await headers() return ... } ``` ## Useful Links - [`headers()` function](/docs/app/api-reference/functions/headers) - [`cookies()` function](/docs/app/api-reference/functions/cookies) - [`draftMode()` function](/docs/app/api-reference/functions/draft-mode) - [`unstable_noStore()` function](/docs/app/api-reference/functions/unstable_noStore) - [`unstable_cache()` function](/docs/app/api-reference/functions/unstable_cache)