vercel/next.js · error · Error
Invalid redirect arguments. Please use a single argument URL
Error message
Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination'). What it means
Thrown by redirect() (wired to res.redirect in API routes) when the arguments do not match the two accepted signatures: a single string URL, or a numeric status code plus a string URL. This protects against ambiguous calls and ensures a valid HTTP redirect is emitted.
Source
Thrown at packages/next/src/server/api-utils/index.ts:68
}
/**
*
* @param res response object
* @param [statusOrUrl] `HTTP` status code of redirect
* @param url URL of redirect
*/
export function redirect(
res: NextApiResponse,
statusOrUrl: string | number,
url?: string
): NextApiResponse<any> {
if (typeof statusOrUrl === 'string') {
url = statusOrUrl
statusOrUrl = 307
}
if (typeof statusOrUrl !== 'number' || typeof url !== 'string') {
throw new Error(
`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`
)
}
res.writeHead(statusOrUrl, { Location: url })
res.write(url)
res.end()
return res
}
export function checkIsOnDemandRevalidate(
rawHeaders: Headers | IncomingHttpHeaders,
previewProps: __ApiPreviewProps
): {
isOnDemandRevalidate: boolean
revalidateOnlyGenerated: boolean
} {
// Headers is a plain object for Node.js, Headers object in Edge runtime
if (typeof rawHeaders.get === 'function') {View on GitHub (pinned to 0ae8c72462)
Solutions
- Use res.redirect('/destination') for a default 307 redirect.
- Use res.redirect(307, '/destination') — number first, then string URL.
- Ensure the status code is a number (not a string) and the URL is a string.
Example fix
// before
res.redirect('/dest', 307) // wrong order
res.redirect(307) // missing url
// after
res.redirect('/dest')
res.redirect(307, '/dest') Defensive patterns
Strategy: type-guard
Validate before calling
function safeRedirect(res: any, statusOrUrl: string | number, url?: string) {
if (typeof statusOrUrl === 'string') { res.redirect(statusOrUrl); return }
if (typeof statusOrUrl === 'number' && typeof url === 'string') { res.redirect(statusOrUrl, url); return }
throw new Error('Invalid redirect arguments')
} Type guard
function isValidRedirectArgs(statusOrUrl: unknown, url?: unknown): boolean {
if (typeof statusOrUrl === 'string' && url === undefined) return true
if (typeof statusOrUrl === 'number' && typeof url === 'string') return true
return false
} Prevention
- Use res.redirect('/path') or res.redirect(307, '/path') — number first.
- Do not pass two strings or reversed argument order.
- Ensure status codes are numbers, not strings.
When it happens
Trigger: Calling res.redirect() with no arguments, with two strings, with a non-number/non-string mix, or with a status that isn't a number. The check at line 67 fails when statusOrUrl isn't a number or url isn't a string after the single-string normalization.
Common situations: Passing res.redirect(url, status) in the wrong order (a common mistake from Express differences); calling res.redirect(200); res.redirect(undefined); or res.redirect(status, url) where status came in as a string.
Related errors
- Invalid urlPath provided to revalidate(), must be a path e.g
- `after()`: Argument must be a promise or a function
- Preview data is limited to 2KB currently, reduce how much da
- Invalid response ${res.status}
- Failed to revalidate ${urlPath}: ${err.message}
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/07bad45471ca93e6.
Report an issue: GitHub.