{"record":{"id":"bcb69477076eb37a","repo":"pydantic/monty","slug":"monty-create-could-not-auto-load-the-monty-wasm-module-in","errorCode":null,"errorMessage":"Monty.create could not auto-load the monty wasm module in this environment; compile it yourself and call createWorkerPool(modules) instead","messagePattern":"Monty\\.create could not auto-load the monty wasm module in this environment; compile it yourself and call createWorkerPool\\(modules\\) instead","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/worker/index.ts","lineNumber":53,"sourceCode":"\n/** Creates a pool over the best backend for this environment. */\nexport async function createWorkerPool(modules: ComponentModules, options: WasmPoolOptions = {}): Promise<WorkerPool> {\n  const requestTimeoutMs = options.requestTimeout === undefined ? undefined : options.requestTimeout * 1000\n  const factory: WorkerFactory =\n    'Worker' in globalThis\n      ? browserWorkerFactory(modules, { requestTimeoutMs }, options.workerUrl)\n      : inProcessFactory(modules)\n  return WorkerPool.create(factory, {\n    minWorkers: options.minProcesses,\n    maxWorkers: options.maxProcesses,\n    maxCheckoutsPerWorker: options.maxCheckoutsPerWorker,\n  })\n}\n\n/** Loads the bundled wasm module and creates a browser/worker-backed pool. */\nexport class Monty {\n  static async create(_options: WasmPoolOptions = {}): Promise<WorkerPool> {\n    throw new Error(\n      'Monty.create could not auto-load the monty wasm module in this environment; ' +\n        'compile it yourself and call createWorkerPool(modules) instead',\n    )\n  }\n}\n\nexport { WorkerPool, inProcessFactory } from './pool.js'\nexport {\n  FunctionSnapshot,\n  FutureSnapshot,\n  MontyComplete,\n  MontySession,\n  NameLookupSnapshot,\n  NOT_HANDLED,\n} from '../session.js'\nexport type {\n  ExternalFunction,\n  FeedOptions,","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/worker/index.ts#L35-L71","documentation":"`Monty.create()` is only a convenience auto-loader for the bundled wasm module; when it cannot locate/load the compiled component in the current environment it throws this error instead of failing mysteriously later. The library expects you to build the wasm component yourself (e.g. `make build-wasm`) and hand the resulting component modules directly to `createWorkerPool(modules)`. This keeps the JS package from shipping an environment-specific binary loader it cannot guarantee works.","triggerScenarios":"Calling `Monty.create(options)` in an environment where the bundled wasm module could not be auto-loaded — e.g. a browser/bundler setup where the component was never compiled or the auto-load path is not supported for the current module format.","commonSituations":"Consumers install `@pydantic/monty/wasm` from npm without building the wasm component locally; bundlers (Vite/webpack) fail to resolve the auto-load import; CI environments lack the `wasm32-wasip1` target build artifact; developers call the browser `Monty` entry point expecting the same auto-loading as the napi/native path.","solutions":["Build the wasm component yourself: run `make build-wasm` (requires the wasm32-wasip1 target) in the repo.","Import `createWorkerPool` from `@pydantic/monty/wasm` and pass the compiled `ComponentModules` to it directly instead of calling `Monty.create()`.","Verify the module files you pass are the checked-in WIT-derived declarations/exports produced by the build, not stale or hand-edited copies.","If you cannot build locally, use the native napi pool (`Monty.create()` from the package root) which runs workers via the `monty` binary instead of wasm."],"exampleFix":"// before\nimport { Monty } from '@pydantic/monty/wasm'\nconst pool = await Monty.create()\n\n// after\nimport { createWorkerPool } from '@pydantic/monty/wasm'\nimport modules from './compiled-monty-component.js' // output of `make build-wasm`\nconst pool = await createWorkerPool(modules)","handlingStrategy":"fallback","validationCode":"import { Monty, createWorkerPool } from '@pydantic/monty/wasm'\nlet pool\ntry {\n  pool = await Monty.create()\n} catch {\n  pool = await createWorkerPool(requireCompiledModules())\n}","typeGuard":"function canAutoLoad(): boolean {\n  try { return typeof Monty !== 'undefined' } catch { return false }\n}","tryCatchPattern":"let pool: WorkerPool\ntry {\n  pool = await Monty.create(options)\n} catch (err) {\n  if (!(err instanceof Error) || !err.message.includes('auto-load')) throw err\n  pool = await createWorkerPool(compiledModules)\n}","preventionTips":["Always pre-build the wasm component (make build-wasm) in environments targeting the wasm path.","Prefer calling createWorkerPool(modules) directly when you control the build pipeline.","Keep the compiled component and the JS package versions in lockstep.","Use the native napi pool when a host binary is available instead of wasm."],"tags":["wasm","browser","wasm-worker","module-loading"],"backgroundTag":"module-init-failed","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}