Skip to content

Error: ServerContext: [context] already defined #55750

Closed
@marozzocom

Description

@marozzocom

Link to the code that reproduces this issue

https://github.com/marozzocom/server-context

To Reproduce

  1. Start the application in development by running npm run dev
  2. Observe the text under the Next.js logo ("Hello from Server Context!")
  3. Refresh the page with ⌘+R or otherwise

Current vs. Expected behavior

Expected behaviour
Page renders again as before.

Current behaviour
The following error message, that will only be reset by restarting the development server:

image
Uncaught Error: ServerContext: server-context already defined
    at t.createServerContext (file:///obfuscated_path/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js:1:505978)
    at eval (webpack-internal:///obfuscated_module_path:9:81)
    at obfuscated_module_path (file:///obfuscated_path/.next/server/app/page.js:183:1)
    at __webpack_require__ (file:///obfuscated_path/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///obfuscated_module_path:10:88)
    at obfuscated_module_path (file:///obfuscated_path/.next/server/app/page.js:194:1)
    at Function.__webpack_require__ (file:///obfuscated_path/.next/server/webpack-runtime.js:33:42)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:538:9)
    at process.processTimers (node:internal/timers:512:7)
    at async Ce (file:///obfuscated_path/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js:1:601910)
    at async Xe.tree (file:///obfuscated_path/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js:1:607885)
    at async Xe (file:///obfuscated_path/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js:1:607711)
    at async Qe (file:///obfuscated_path/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js:1:608793)
    at async (file:///obfuscated_path/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js:1:612260)

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.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
Binaries:
  Node: 18.18.0
  npm: 9.8.1
  Yarn: 3.4.1
  pnpm: 8.7.6
Relevant Packages:
  next: 13.5.3-canary.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

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

App Router

Additional context

Issue introduced in
This issue appears in 13.4.20-canary.32 and later releases.

Additional info
The error only appears during development mode, and is not present when running a production build.

I was able to also reproduce this in a Codesandbox environment. In Codesandbox, an edit of the page and the following hot refresh seems to be needed to trigger the error.

I also tested a deployment into Vercel. Since it runs a production build, there is no error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions