clockworklabs/SpacetimeDB · error · anyhow::Error

must export schema as default export

Error message

must export schema as default export

What it means

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.

Solutions

  1. Add `export default` of the module definition (RawModuleDef/schema object) to the entry file.
  2. Inspect the built bundle to confirm the default export survived bundling.
  3. Start from the current SDK's quickstart template to match the exact expected shape.
  4. Match SDK and host versions.

Example fix

// before
export const module = new RawModuleDef('my-module'); // named export only

// after
const module = new RawModuleDef('my-module');
// ... register tables/reducers on `module` ...
export default module;
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
const src = fs.readFileSync('dist/module.js', 'utf8');
if (!/export\s+default/.test(src)) {
  throw new Error('bundle has no default export; publish would fail');
}

Try / catch

Catch the publish/startup error and point module authors at the default-export requirement; the message already states it.

Prevention

When it happens

Trigger: 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.

Common situations: Bundler misconfiguration producing named exports only; copying examples from a different SDK major version; the default export lost during TS transpilation.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20). Data as JSON: /api/errors/1c55ab1360de07f5. Report an issue: GitHub.

Appendix: source

Thrown at crates/core/src/host/v8/mod.rs:1200

        None
    }
}

/// Performs some of the shared startup work for JS worker isolates.
///
/// NOTE(centril): in its own function due to lack of `try` blocks.
fn startup_instance_worker<'scope>(
    scope: &mut PinScope<'scope, '_>,
    program: Arc<str>,
    module_or_mcc: Either<ModuleCommon, ModuleCreationContext>,
) -> anyhow::Result<(HookFunctions<'scope>, ModuleCommon)> {
    let hook_functions = catch_exception(scope, |scope| {
        // Start-up the user's module.
        let exports_obj = eval_user_module(scope, &program)?;

        // Find the hook functions.
        let hooks =
            get_hooks(scope, exports_obj)?.ok_or_else(|| anyhow::anyhow!("must export schema as default export"))?;
        Ok(hooks)
    })?;

    // If we don't have a module, make one.
    let module_common = match module_or_mcc {
        Either::Left(module_common) => module_common,
        Either::Right(mcc) => {
            let def = extract_description(scope, &hook_functions, &mcc.replica_ctx)?;

            // Validate and create a common module from the raw definition.
            build_common_module_from_raw(mcc, def)?
        }
    };

    Ok((hook_functions, module_common))
}

/// Returns a new isolate.

View on GitHub (pinned to eddf9f5014)