EXT nextjs server-actions ai_generated true

Error: NEXT_REDIRECT

ID: nextjs/server-action-redirect-error

Also available as: JSON · Markdown
94%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
14 active

Root Cause

redirect() in a try/catch block — Next.js redirect throws a special error that must propagate.

generic

Workarounds

  1. 95% success Move redirect() outside the try/catch block, or re-throw NEXT_REDIRECT errors
    if (error.digest?.includes('NEXT_REDIRECT')) throw error

    Sources: https://nextjs.org/docs/app/api-reference/functions/redirect

  2. 90% success Use the redirect after the try/catch: try { ... } catch { ... } redirect('/path')
    Place redirect at the end of the function where it can propagate freely

Dead Ends

Common approaches that don't work:

  1. Catching and ignoring the error 80% fail

    The redirect never happens; the action appears to do nothing

  2. Using router.push() in the server action 85% fail

    router is a client-side API; not available in server actions

Error Chain

Frequently confused with: