sveltejs/kit · error · Error
called uneval before init_transport
Error message
called uneval before init_transport
What it means
uneval is a stub that SvelteKit replaces via init_transport when the server rendering pipeline initializes the devalue transport. If code calls uneval before that initialization, the stub throws in dev (and throws a blank error in prod). It signals an out-of-order or out-of-context call of an internal serialization hook.
Source
Thrown at packages/kit/src/runtime/app/internal/transport.js:7
/** @import { Transport } from '@sveltejs/kit/hooks' */
import * as devalue from 'devalue';
import { DEV } from 'esm-env';
/** @type {(thing: any) => string} */
export let uneval = () => {
throw new Error(DEV ? 'called uneval before init_transport' : '');
};
/** @type {(data: any) => string} */
export let stringify = () => {
throw new Error(DEV ? 'called stringify before init_transport' : '');
};
/** @type {(data: string) => any} */
export let parse = () => {
throw new Error(DEV ? 'called parse before init_transport' : '');
};
/** @type {Record<string, (data: any) => any>} */
export let encoders = {};
/** @type {Record<string, (data: any) => any>} */
export let decoders = {};
View on GitHub (pinned to 03f1687fe6)
Solutions
- Call uneval only within the request lifecycle managed by SvelteKit (e.g. inside load or server hooks), not in server bootstrap code
- Use `devalue.stringify`/`uneval` from the devalue package directly if you need standalone serialization
- If you maintain an adapter, ensure init_transport is invoked before rendering
- Update @sveltejs/kit; this internal API changed with the transport refactor
Example fix
// before
import { uneval } from '@sveltejs/kit/internal'; // outside render
// after
import { stringify } from 'devalue';
const s = stringify(data); Defensive patterns
Strategy: try-catch
Validate before calling
import { uneval } from 'your-transport-module';
if (typeof uneval.__initialized !== 'boolean') {
throw new Error('transport not initialized: call init_transport first');
} Try / catch
try {
const js = uneval(data);
} catch (e) {
if (e.message === 'called uneval before init_transport') {
// serialize outside kit with devalue instead
} else throw e;
} Prevention
- Only call kit transport helpers inside the kit request lifecycle
- Use the devalue package directly for standalone serialization
- Initialize transport (init_transport) before any custom rendering that serializes data
- Avoid importing kit internal transport modules directly
When it happens
Trigger: Calling the exported uneval from @sveltejs/kit (or reaching this module) before init_transport has run — typically custom server code or a plugin invoking server-side serialization outside a request render handled by SvelteKit.
Common situations: Calling transport/uneval utilities from adapter hooks or custom server entry points before kit initializes, importing internals directly, or tests invoking uneval without setting up kit's render pipeline.
Related errors
- called stringify before init_transport
- called parse before init_transport
- Data returned from action inside ${route_id} is not serializ
- Data returned from action inside ${route_id} is not serializ
- Invalid data for Set reviver
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/e1301de006a7f5be.
Report an issue: GitHub.