{"record":{"id":"c40676c0ea8ff716","repo":"sveltejs/kit","slug":"called-stringify-before-init-transport","errorCode":null,"errorMessage":"called stringify before init_transport","messagePattern":"called stringify before init_transport","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/internal/transport.js","lineNumber":12,"sourceCode":"/** @import { Transport } from '@sveltejs/kit/hooks' */\nimport * as devalue from 'devalue';\nimport { DEV } from 'esm-env';\n\n/** @type {(thing: any) => string} */\nexport let uneval = () => {\n\tthrow new Error(DEV ? 'called uneval before init_transport' : '');\n};\n\n/** @type {(data: any) => string} */\nexport let stringify = () => {\n\tthrow new Error(DEV ? 'called stringify before init_transport' : '');\n};\n\n/** @type {(data: string) => any} */\nexport let parse = () => {\n\tthrow new Error(DEV ? 'called parse before init_transport' : '');\n};\n\n/** @type {Record<string, (data: any) => any>} */\nexport let encoders = {};\n\n/** @type {Record<string, (data: any) => any>} */\nexport let decoders = {};\n\nexport let has_custom_transporters = false;\n\n/**\n *\n * @param {Transport} transport","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/internal/transport.js#L1-L30","documentation":"stringify is a stub replaced by init_transport once SvelteKit's render pipeline sets up the devalue transport. Calling it before initialization throws in dev. This guards against serializing data outside the context where transport encoders are registered.","triggerScenarios":"Invoking the exported stringify from the transport module (or code paths relying on it) before init_transport runs — e.g. custom server code, adapters, or tests calling serialization before kit's render setup.","commonSituations":"Importing internal transport utilities directly, custom adapters serializing data outside a kit-handled request, or unit tests without kit's pipeline initialization.","solutions":["Only serialize within kit's request lifecycle (load functions, hooks) where init_transport has already run","Use the `devalue` package's stringify directly for standalone serialization","If building a custom adapter/renderer, call init_transport before using stringify","Update @sveltejs/kit to the latest version"],"exampleFix":"// before\nimport { stringify } from '@sveltejs/kit/internal';\n// after\nimport { stringify } from 'devalue';","handlingStrategy":"try-catch","validationCode":"import { stringify } from 'your-transport-module';\nif (typeof encoders !== 'object' || Object.keys(encoders).length === 0) {\n  throw new Error('transport not initialized: call init_transport first');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const json = stringify(data);\n} catch (e) {\n  if (e.message === 'called stringify before init_transport') {\n    const json = devalueStringify(data); // fallback\n  } else throw e;\n}","preventionTips":["Serialize only within load functions/hooks where kit has initialized the transport","Use devalue.stringify for custom serialization needs","Ensure custom adapters/renderers call init_transport first","Do not import transport internals in application code"],"tags":["serialization","devalue","transport","initialization-order"],"backgroundTag":"called-before-init-transport","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}