Skip to content

[NEXT-1181] DynamicServerError: Dynamic server usage: cookies #49373

@focux

Description

@focux

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.13.2
      npm: 9.3.0
      Yarn: 1.22.19
      pnpm: 7.25.1
    Relevant packages:
      next: 13.4.1
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/focux/next-cookies-bug

To Reproduce

  1. Clone the repository
  2. Run npm run build

Describe the Bug

After upgrading to Next from 13.3.5 to 13.4.1, I'm getting a lot of errors that say:

- info Creating an optimized production build ..node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

DynamicServerError: Dynamic server usage: cookies
    at staticGenerationBailout (/Users/[redacted]/Projects/[redacted]/apps/web-app/.next/server/chunks/3311.js:46379:21)
    at cookies (/Users/[redacted]/Projects/[redacted]/apps/web-app/.next/server/chunks/6647.js:172:62)
    at getAccessToken (/Users/[redacted]/Projects/[redacted]/apps/web-app/.next/server/chunks/9041.js:30473:40)
    at /Users/[redacted]/Projects/[redacted]/apps/web-app/.next/server/chunks/9041.js:30505:55
    at /Users/[redacted]/Projects/[redacted]/apps/web-app/.next/server/chunks/6647.js:2598:44 {
  digest: 'DYNAMIC_SERVER_USAGE'
}

The app works good when running it on development mode.

Expected Behavior

According to the docs, using the cookies function automatically opt-ins my pages to dynamic rendering.

So I would expect the build to succeed as before and also those errors to be clearer to at least know in what page is originating.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1181

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions