Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware not working with latest version of Next Js

See original GitHub issue

Package + Version

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/clerk-expo
  • @clerk/backend-core
  • @clerk/clerk-sdk-node
  • @clerk/edge
  • other:




If applicable e.g. Chrome latest


Currently when running the latest version of Next Js 12.2.0 the following code:

export default withEdgeMiddlewareAuth((req) => {

Throws the error: [Error: A middleware can not alter response's body. Learn more:]

The documentation could also be updated in the clerk docs to support the changes to Next Js middleware in general, which now requires middleware to be at the root of the application.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

SokratisVidroscommented, Jul 4, 2022

Sure thing. We have already started a draft PR but it needs more work as the changes on Next.js side were big.

SokratisVidroscommented, Jul 10, 2022

Yes. We will continue working on Next 12.2 so as to move authentication completely in the middleware.ts but our latest release should unblock you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

next.js - NextJS middleware does not seem to be triggered
Latest versions of NextJS requires user to have a single middleware on the root folder. To be more precise, the middleware file has...
Read more >
middleware not working · Discussion #38546 · vercel/next.js
Is there any drawback to making middleware.ts a "reserved" filename? Seems simpler and is similar to the conventions of the new layouts system...
Read more >
Advanced Features: Middleware - Next.js
Learn how to use Middleware to run code before a request is completed. ... Install the latest version of Next.js: npm install next@latest....
Read more >
How to use middleware in nextjs? - Medium
Nextjs middleware does not run with typescript and throws an error in the terminal. You install typescript, and right now, you do not...
Read more >
What's New in Next.js 13 - AppSignal Blog
Version 13 of Next.js, a well-established React framework from the ... When you deal with pages/index.tsx , the running Next.js server will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found