Verify 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
- Create new Next app
- Add middleware
- 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
Verify 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/AWhich 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
server-onlywithimport "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