{"record":{"id":"1c55ab1360de07f5","repo":"clockworklabs/SpacetimeDB","slug":"must-export-schema-as-default-export","errorCode":null,"errorMessage":"must export schema as default export","messagePattern":"must export schema as default export","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/core/src/host/v8/mod.rs","lineNumber":1187,"sourceCode":"        None\n    }\n}\n\n/// Performs some of the shared startup work for JS worker isolates.\n///\n/// NOTE(centril): in its own function due to lack of `try` blocks.\nfn startup_instance_worker<'scope>(\n    scope: &mut PinScope<'scope, '_>,\n    program: Arc<str>,\n    module_or_mcc: Either<ModuleCommon, ModuleCreationContext>,\n) -> anyhow::Result<(HookFunctions<'scope>, ModuleCommon)> {\n    let hook_functions = catch_exception(scope, |scope| {\n        // Start-up the user's module.\n        let exports_obj = eval_user_module(scope, &program)?;\n\n        // Find the hook functions.\n        let hooks =\n            get_hooks(scope, exports_obj)?.ok_or_else(|| anyhow::anyhow!(\"must export schema as default export\"))?;\n        Ok(hooks)\n    })?;\n\n    // If we don't have a module, make one.\n    let module_common = match module_or_mcc {\n        Either::Left(module_common) => module_common,\n        Either::Right(mcc) => {\n            let def = extract_description(scope, &hook_functions, &mcc.replica_ctx)?;\n\n            // Validate and create a common module from the raw definition.\n            build_common_module_from_raw(mcc, def)?\n        }\n    };\n\n    Ok((hook_functions, module_common))\n}\n\n/// Returns a new isolate.","sourceCodeStart":1169,"sourceCodeEnd":1205,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/core/src/host/v8/mod.rs#L1169-L1205","documentation":"When a JavaScript (V8) module starts, the host evaluates the module, reads its default export, and derives the hook functions (reducers, tables, lifecycle) from it. Here get_hooks returned None: the module did not yield hooks from a default export, most simply because no usable default export exists. Without it the host cannot build the module description, so instance startup fails.","triggerScenarios":"Publishing a JS module whose bundle does not export the schema object as the default export: a missing export statement, a bundler step that dropped or renamed the default export, or a module built against bindings that do not produce the expected export shape.","commonSituations":"Bundler configs (minification, library mode) that rewrite or drop default exports; modules written against an old bindings generation whose export convention differs from the host's ABI expectations; partially uploaded or truncated JS bundles.","solutions":["Ensure the module entry default-exports the schema the bindings generate: `export default schema;`.","Rebuild the bundle and inspect the dist output to confirm the default export survived bundling.","Regenerate or upgrade the JS bindings so the module is built for the ABI version the host expects.","Reproduce locally against the same host version before republishing."],"exampleFix":"// before: schema built but never exported as default\nexport const reducers = { /* ... */ };\n\n// after: default-export the schema object the host expects\nconst schema = buildSchema({ /* ... */ });\nexport default schema;","handlingStrategy":"validation","validationCode":"// pre-deploy smoke check (Node): the built bundle must default-export the schema\nconst mod = await import('./dist/module.js');\nif (mod.default === undefined) {\n    throw new Error('module must default-export its schema');\n}","typeGuard":"export function isSchemaExport(v: unknown): v is { reducers: Record<string, unknown> } {\n  return typeof v === 'object' && v !== null && 'reducers' in v;\n}","tryCatchPattern":null,"preventionTips":["Always `export default schema` from the generated bindings.","Smoke-test the built bundle's exports in CI before deploy.","Regenerate bindings whenever the host version changes."],"tags":["v8","javascript","module-startup","default-export"],"backgroundTag":"missing-default-export","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}