{"record":{"id":"1c60352ed7de9a2a","repo":"dotnet/runtime","slug":"module-ready-couldn-t-be-redefined","errorCode":null,"errorMessage":"Module.ready couldn't be redefined.","messagePattern":"Module\\.ready couldn't be redefined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/loader/run.ts","lineNumber":301,"sourceCode":"}\n\nlet emscriptenPrepared = false;\nasync function prepareEmscripten (moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)) {\n    if (emscriptenPrepared) {\n        return;\n    }\n    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}`);","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/loader/run.ts#L283-L319","documentation":"Thrown by prepareEmscripten when the moduleFactory callback returns an object that has a `ready` property. The Emscripten module's `ready` field is reserved/managed internally by the runtime, so the runtime refuses to let user config redefine it.","triggerScenarios":"Produced when createDotnetRuntime is called with a moduleFactory function whose returned config object includes a `ready` key (e.g. { ready: ... }).","commonSituations":"Copying an Emscripten-style config that sets Module.ready; migrating from a raw Emscripten setup into the dotnet runtime builder; a third-party wrapper that injects ready.","solutions":["Remove the `ready` property from the config object returned by your moduleFactory callback.","If you need a ready signal, use the returned RuntimeAPI promise (await createDotnetRuntime(...)) or the runtime's ready event instead of setting Module.ready.","Pass only supported DotnetModuleConfig keys in the callback."],"exampleFix":"// before: factory returns config with ready\n// createDotnetRuntime(() => ({ ready: myPromise, config: {...} }));\n\n// after: drop ready; use the returned promise\nconst dotnet = await createDotnetRuntime(() => ({ config: {...} }));\n// dotnet is ready once the promise resolves","handlingStrategy":"validation","validationCode":"const factory = () => {\n  const cfg = { config: monoConfig };\n  delete (cfg as any).ready; // never return ready\n  return cfg;\n};","typeGuard":"function configHasNoReady(cfg: any): boolean {\n  return cfg == null || typeof cfg !== 'object' || !('ready' in cfg);\n}","tryCatchPattern":null,"preventionTips":["Never set Module.ready in user config; rely on the createDotnetRuntime promise instead.","Audit config objects copied from Emscripten samples before passing them in.","Only pass documented DotnetModuleConfig keys."],"tags":["startup","config","emscripten","host"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}