vercel/next.js · error · Error
Could not determine origin for forwarded Server Actions requ
Error message
Could not determine origin for forwarded Server Actions request. This can happen if port or hostname are not configured for this server.
What it means
Raised inside createForwardedActionResponse() when a Server Action must be forwarded to a different worker but the server origin cannot be resolved. The code first checks process.env.__NEXT_PRIVATE_ORIGIN; if undefined it tries to derive the origin from the request's initURL via new URL(). If that URL parsing throws, this error is raised with the parse error as cause. It indicates the deployment is missing the private origin/host configuration needed for inter-worker action forwarding.
Source
Thrown at packages/next/src/server/app-render/action-handler.ts:239
}
const forwardedHeaders = getForwardedHeaders(req, res)
// indicate that this action request was forwarded from another worker
// we use this to skip rendering the flight tree so that we don't update the UI
// with the response from the forwarded worker
forwardedHeaders.set('x-action-forwarded', '1')
// TODO: Remove __NEXT_PRIVATE_ORIGIN
let origin: string | undefined = process.env.__NEXT_PRIVATE_ORIGIN
if (origin === undefined) {
const initUrl = getRequestMeta(req, 'initURL')
if (initUrl !== undefined) {
try {
const parsedUrl = new URL(initUrl)
origin = parsedUrl.origin
} catch (error) {
throw new Error(
'Could not determine origin for forwarded Server Actions request. This can happen if port or hostname are not configured for this server.',
{ cause: error }
)
}
} else {
throw new InvariantError('Missing initURL')
}
}
const fetchUrl = new URL(`${origin}${basePath}${workerPathname}`)
try {
let body: BodyInit | ReadableStream<Uint8Array> | undefined
if (
// The type check here ensures that `req` is correctly typed, and the
// environment variable check provides dead code elimination.
process.env.NEXT_RUNTIME === 'edge' &&
isWebNextRequest(req)View on GitHub (pinned to 0ae8c72462)
Solutions
- Set the __NEXT_PRIVATE_ORIGIN environment variable to the server's reachable origin, e.g. 'http://localhost:3000' (or the internal host:port). This is the primary documented fix.
- Ensure the runtime has a valid HOSTNAME and PORT configured so the request initURL can resolve to an absolute URL.
- If using a custom server or standalone mode, verify the server binds to a concrete host/port and that initURL metadata is populated.
- On platforms, confirm the platform adapter forwards the correct host/initURL metadata to Next.js.
Example fix
// before: missing origin env // (no __NEXT_PRIVATE_ORIGIN set) // after: set the private origin for inter-worker forwarding // __NEXT_PRIVATE_ORIGIN=http://localhost:3000
Defensive patterns
Strategy: validation
Validate before calling
// Validate env before booting the server in multi-worker setups.
function assertActionForwardingConfig() {
if (process.env.__NEXT_PRIVATE_ORIGIN === undefined && !process.env.HOSTNAME) {
throw new Error('Set __NEXT_PRIVATE_ORIGIN or HOSTNAME for Server Action forwarding')
}
} Type guard
function isAbsoluteUrl(value: unknown): value is string {
if (typeof value !== 'string') return false
try { new URL(value); return true } catch { return false }
} Prevention
- Set __NEXT_PRIVATE_ORIGIN in all self-hosted/multi-worker deployments.
- Document required env vars (HOSTNAME, PORT, __NEXT_PRIVATE_ORIGIN) in your deployment runbook.
- Add a startup health check that fails fast if origin cannot be derived.
- Test Server Action forwarding in staging with the same env as production.
When it happens
Trigger: A Server Action request arrives at a worker that does not own the action (multi-worker/self-hosted Next.js), so createForwardedActionResponse is invoked. __NEXT_PRIVATE_ORIGIN is not set, and getRequestMeta(req,'initURL') returns a value that is not a valid absolute URL (e.g. a relative path, or undefined-leading-to-the-else-branch won't hit this but a malformed URL will). new URL() throws and this error propagates.
Common situations: Self-hosted Next.js behind a load balancer without setting __NEXT_PRIVATE_ORIGIN; a custom server or standalone output where hostname/port env vars are absent; misconfigured platform that passes a relative or malformed initURL. Common after migrating from Vercel (which sets these) to a self-hosted runtime.
Related errors
- Server Action "${actionId}" was not found on the server. Re
- Invalid Server Action payload: failed to decrypt.
- Failed to link project ${linkRes.stdout} ${linkRes.stderr} (
- Failed to deploy project ${linkRes.stdout} ${linkRes.stderr}
- @next/font/google failed to run or is incorrectly configured
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/d361406bcde76ade.
Report an issue: GitHub.