NEXT_REDIRECT ▲ Next.js

Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)

redirect() works by throwing a special error; catching it in try/catch (or a .catch) swallows the redirect and logs NEXT_REDIRECT.

Seen on: Next.js

Meaning

In Server Actions and Server Components, redirect() and notFound() throw control-flow errors. Call them outside try/catch, or rethrow them using unstable_rethrow / isRedirectError.

Common causes

  • redirect() called inside try { }
  • Generic catch logging all errors
  • Wrapping server action logic in try/catch

⚡ Quick fix

  1. Move redirect() after the try/catch block
  2. Rethrow framework errors with unstable_rethrow(error)
  3. Return a value and redirect afterwards

Detailed fix by platform

TypeScript

  1. tsx
    export async function createPost(form: FormData) {
      "use server";
      let id: string;
      try { id = await db.post.create(form); } catch (e) { return { error: "Failed" }; }
      redirect(`/posts/${id}`);
    }

How to diagnose

  1. Location — Is redirect() inside try?
  2. Catch — Does it swallow errors?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.