Skip to content

middleware.ts treated as a client side component #54549

@mansdahlstrom1

Description

@mansdahlstrom1

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.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.20.0
      npm: 8.19.4
      Yarn: 1.22.19
      pnpm: 8.4.0
    Relevant Packages:
      next: 13.4.20-canary.6
      eslint-config-next: 13.4.19
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

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

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/mansdahlstrom1/middleware-client-component-bug

To Reproduce

  1. Create new Next app
  2. Add middleware
  3. mark middleware as server-only with import "server-only";

Describe the Bug

When using middleware we expect the middleware to run server-side only and to be able to use features like Cookies etc. But we are not able to do this as Next seem to think that the middleware is running client side.

Expected Behavior

MIddleware can be marked as server-only. Server side only features work in middleware.ts file.

OR

Clearer error message that explains the real error.

Which browser are you using? (if relevant)

116.0.5845.110

How are you deploying your application? (if relevant)

No response

NEXT-1607

Metadata

Metadata

Assignees

No one assigned

    Labels

    RuntimeRelated to Node.js or Edge Runtime with Next.js.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