pydantic/monty · error · Error
Monty.create could not auto-load the monty wasm module in th
Error message
Monty.create could not auto-load the monty wasm module in this environment; compile it yourself and call createWorkerPool(modules) instead
What it means
`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.
Source
Thrown at crates/monty-js/ts/worker/index.ts:53
/** Creates a pool over the best backend for this environment. */
export async function createWorkerPool(modules: ComponentModules, options: WasmPoolOptions = {}): Promise<WorkerPool> {
const requestTimeoutMs = options.requestTimeout === undefined ? undefined : options.requestTimeout * 1000
const factory: WorkerFactory =
'Worker' in globalThis
? browserWorkerFactory(modules, { requestTimeoutMs }, options.workerUrl)
: inProcessFactory(modules)
return WorkerPool.create(factory, {
minWorkers: options.minProcesses,
maxWorkers: options.maxProcesses,
maxCheckoutsPerWorker: options.maxCheckoutsPerWorker,
})
}
/** Loads the bundled wasm module and creates a browser/worker-backed pool. */
export class Monty {
static async create(_options: WasmPoolOptions = {}): Promise<WorkerPool> {
throw new Error(
'Monty.create could not auto-load the monty wasm module in this environment; ' +
'compile it yourself and call createWorkerPool(modules) instead',
)
}
}
export { WorkerPool, inProcessFactory } from './pool.js'
export {
FunctionSnapshot,
FutureSnapshot,
MontyComplete,
MontySession,
NameLookupSnapshot,
NOT_HANDLED,
} from '../session.js'
export type {
ExternalFunction,
FeedOptions,View on GitHub (pinned to adc986b362)
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.
Example fix
// before
import { Monty } from '@pydantic/monty/wasm'
const pool = await Monty.create()
// after
import { createWorkerPool } from '@pydantic/monty/wasm'
import modules from './compiled-monty-component.js' // output of `make build-wasm`
const pool = await createWorkerPool(modules) Defensive patterns
Strategy: fallback
Validate before calling
import { Monty, createWorkerPool } from '@pydantic/monty/wasm'
let pool
try {
pool = await Monty.create()
} catch {
pool = await createWorkerPool(requireCompiledModules())
} Type guard
function canAutoLoad(): boolean {
try { return typeof Monty !== 'undefined' } catch { return false }
} Try / catch
let pool: WorkerPool
try {
pool = await Monty.create(options)
} catch (err) {
if (!(err instanceof Error) || !err.message.includes('auto-load')) throw err
pool = await createWorkerPool(compiledModules)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- the wasm worker does not support filesystem mounts (browser
- component core module is missing: ${path}
- Dump returned an unexpected event
- ${what} produced no turn-ending event (worker crashed)
- ${what} expected event ${kind}, got ${event.tag}
AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13).
Data as JSON: /api/errors/bcb69477076eb37a.
Report an issue: GitHub.