Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic server usage Error in build output is misleading when caught inside of a try/catch block #62462

Open
ppiwo opened this issue Feb 23, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template.

Comments

@ppiwo
Copy link

ppiwo commented Feb 23, 2024

Link to the code that reproduces this issue

https://github.com/ppiwo/reproduction-next-app

To Reproduce

  1. Clone repo
  2. Run npm i
  3. Run npm run build

Current vs. Expected behavior

Current

  • Page is correctly rendered as dynamic ✅
  • The error is printed to stdout ❌
CAUGHT:  n [Error]: Dynamic server usage: Route / couldn't be rendered statically because it used headers. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
    at c (/git/reproduction-app/.next/server/chunks/next-runtime.js:6:156144)
    at d (/git/reproduction-app/.next/server/chunks/next-runtime.js:6:111686)
    at i (/git/reproduction-app/.next/server/app/page.js:1:2373)
    at ep (/git/reproduction-app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134542)

Expected

  • The error (meant to be caught by next.js) is not emitted in the build logs

Although this bug doesn't affect the render of the page (static vs dynamic is still inferred correctly) it's difficult to debug unless you dig into implementation details of the framework itself.

  1. The source of the error is difficult to pinpoint from the stack trace
  2. The documentation that is linked in the error message is misleading.

Why This Message Occurred
You attempted to use a Next.js function that depends on Async Context (such as headers or cookies from next/headers) but it was not bound to the same call stack as the function that ran it (e.g., calling cookies() inside of a setTimeout or setInterval).

Based off of this explanation I believe that this exception was only meant to be seen by the user if it was not caught by the framework (probably because it was thrown outside of the callstack of the function that ran it (e.g., calling cookies() inside of a setTimeout or setInterval).

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 3.5.0
  pnpm: 8.6.12
Relevant Packages:
  next: 14.1.1-canary.70 // Latest available version is detected (14.1.1-canary.70).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

@ppiwo ppiwo added the bug Issue was opened via the bug report template. label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

1 participant