{"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":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/v8/mod.rs","lineNumber":1200,"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":1182,"sourceCodeEnd":1218,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/core/src/host/v8/mod.rs#L1182-L1218","documentation":"JS/TS quickstart modules are instantiated by evaluating the bundled program in a v8 isolate and then reading hook functions from its exports. get_hooks returning None means the module did not provide its module/schema definition as the default export, which every JS module must do.","triggerScenarios":"Publishing a JS bundle whose default export was stripped by the bundler or tree-shaker; only named exports present; mixing module styles where hooks are registered but no default export exists.","commonSituations":"Bundler misconfiguration producing named exports only; copying examples from a different SDK major version; the default export lost during TS transpilation.","solutions":["Add `export default` of the module definition (RawModuleDef/schema object) to the entry file.","Inspect the built bundle to confirm the default export survived bundling.","Start from the current SDK's quickstart template to match the exact expected shape.","Match SDK and host versions."],"exampleFix":"// before\nexport const module = new RawModuleDef('my-module'); // named export only\n\n// after\nconst module = new RawModuleDef('my-module');\n// ... register tables/reducers on `module` ...\nexport default module;","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst src = fs.readFileSync('dist/module.js', 'utf8');\nif (!/export\\s+default/.test(src)) {\n  throw new Error('bundle has no default export; publish would fail');\n}","typeGuard":null,"tryCatchPattern":"Catch the publish/startup error and point module authors at the default-export requirement; the message already states it.","preventionTips":["Add a bundling smoke test that imports the bundle and asserts mod.default exists.","Pin the quickstart template for the SDK version in use.","Keep one canonical entry file for the module definition."],"tags":["javascript","module","default-export","v8","publish"],"backgroundTag":"missing-default-export","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}