{"record":{"id":"c607e1fec8e13c54","repo":"dotnet/runtime","slug":"can-t-use-modulefactory-callback-of-createdotnetru","errorCode":null,"errorMessage":"Can't use moduleFactory callback of createDotnetRuntime function.","messagePattern":"Can't use moduleFactory callback of createDotnetRuntime function\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/loader/run.ts","lineNumber":308,"sourceCode":"    emscriptenPrepared = true;\n    if (ENVIRONMENT_IS_WEB && loaderHelpers.config.forwardConsole && typeof globalThis.WebSocket != \"undefined\") {\n        setup_proxy_console(\"main\", globalThis.console, globalThis.location.origin);\n    }\n    mono_assert(emscriptenModule, \"Null moduleConfig\");\n    mono_assert(loaderHelpers.config, \"Null moduleConfig.config\");\n\n    // extract ModuleConfig\n    if (typeof moduleFactory === \"function\") {\n        const extension = moduleFactory(globalObjectsRoot.api) as any;\n        if (extension.ready) {\n            throw new Error(\"Module.ready couldn't be redefined.\");\n        }\n        Object.assign(emscriptenModule, extension);\n        deep_merge_module(emscriptenModule, extension);\n    } else if (typeof moduleFactory === \"object\") {\n        deep_merge_module(emscriptenModule, moduleFactory);\n    } else {\n        throw new Error(\"Can't use moduleFactory callback of createDotnetRuntime function.\");\n    }\n\n    await detect_features_and_polyfill(emscriptenModule);\n}\n\nexport async function createEmscripten (moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)): Promise<RuntimeAPI | EmscriptenModuleInternal> {\n    await prepareEmscripten(moduleFactory);\n\n    if (BuildConfiguration === \"Debug\" && !ENVIRONMENT_IS_WORKER) {\n        mono_log_info(`starting script ${loaderHelpers.scriptUrl}`);\n        mono_log_info(`starting in ${loaderHelpers.scriptDirectory}`);\n    }\n    if (loaderHelpers.config.exitOnUnhandledError) {\n        installUnhandledErrorHandler();\n    }\n\n    registerEmscriptenExitHandlers();\n","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/loader/run.ts#L290-L326","documentation":"Thrown by prepareEmscripten when the moduleFactory argument passed to createDotnetRuntime is neither a function nor a plain object. The runtime accepts only those two shapes for configuring the Emscripten module; anything else is a usage error.","triggerScenarios":"Produced when createDotnetRuntime is invoked with an argument of the wrong type — e.g. a string, a number, null (when not specially handled), an array, or undefined passed where a config/factory is expected.","commonSituations":"Passing the config in the wrong argument position; passing a module namespace/Proxy that typeof reports as something other than 'function' or 'object'; passing undefined by mistake; using an incompatible API wrapper.","solutions":["Pass either a plain DotnetModuleConfig object or a (api) => DotnetModuleConfig function as the moduleFactory argument.","If you have nothing to configure, pass an empty object: createDotnetRuntime({}).","Double-check the createDotnetRuntime signature in your version of the runtime to ensure you pass the factory in the correct position."],"exampleFix":"// before: wrong argument type\n// createDotnetRuntime('./config.json'); // string is invalid\n// createDotnetRuntime(); // undefined\n\n// after: pass an object or a factory function\nawait createDotnetRuntime({ config: monoConfig });\n// or\nawait createDotnetRuntime(api => ({ config: monoConfig }));","handlingStrategy":"type-guard","validationCode":"function isModuleFactory(arg: any): boolean {\n  return typeof arg === 'function' || (typeof arg === 'object' && arg !== null && !Array.isArray(arg));\n}\nif (!isModuleFactory(arg)) { /* pass {} or a (api)=>config function */ }","typeGuard":"function isModuleFactory(arg: unknown): arg is ((api: any) => any) | object {\n  return typeof arg === 'function' || (typeof arg === 'object' && arg !== null && !Array.isArray(arg));\n}","tryCatchPattern":null,"preventionTips":["Pass a plain object or a factory function to createDotnetRuntime.","If you have no config, pass {}.","Check the runtime's createDotnetRuntime signature for your version before integrating."],"tags":["startup","config","host","api-usage"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}