{"record":{"id":"692b49cdbf5a881c","repo":"sveltejs/kit","slug":"called-parse-before-init-transport","errorCode":null,"errorMessage":"called parse before init_transport","messagePattern":"called parse before init_transport","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/internal/transport.js","lineNumber":17,"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\n */\nexport function init_transport(transport) {\n\tconst transporters = Object.entries(transport);\n\n\thas_custom_transporters = transporters.length > 0;","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/internal/transport.js#L1-L35","documentation":"parse is a stub that init_transport replaces with the real devalue-backed parser once the client runtime initializes the transport. Calling it before initialization throws in dev. It indicates the deserialization API is being used before kit's client bootstrap wires up the encoders.","triggerScenarios":"Calling the exported parse before init_transport runs on the client — e.g. custom client code or tests importing the transport internals directly and parsing transport payloads before kit bootstraps.","commonSituations":"Manually parsing `__sveltekit` transport payloads in custom scripts or extensions, unit tests that skip kit's client entry, or older adapters/custom render paths that bypass initialization.","solutions":["Let SvelteKit parse transport data (use the deserialized results in load/​form actions rather than calling parse yourself)","Use `devalue.parse` directly with the proper revivers if you need standalone parsing","Ensure whatever harness/test boots the app loads kit's client entry (which calls init_transport)","Update @sveltejs/kit to the latest version"],"exampleFix":"// before\nimport { parse } from '@sveltejs/kit/internal';\n// after\nimport { parse } from 'devalue';","handlingStrategy":"try-catch","validationCode":"import { parse } from 'your-transport-module';\nif (typeof parse.__initialized !== 'boolean') {\n  throw new Error('client transport not initialized');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const data = parse(payload);\n} catch (e) {\n  if (e.message === 'called parse before init_transport') {\n    // wait for client bootstrap or use devalue.parse with revivers\n  } else throw e;\n}","preventionTips":["Let SvelteKit hydrate and deserialize transport payloads automatically","If parsing manually, wait until after kit's client entry has run","Use devalue.parse with the same encoders used server-side for custom flows","Do not import kit internal transport modules in app code"],"tags":["serialization","devalue","transport","client","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"}