vitejs/vite · error · Error
Failed to parse WASM file "${wasmFilePath}": ${(e as Error).
Error message
Failed to parse WASM file "${wasmFilePath}": ${(e as Error).message} What it means
parseWasm (packages/vite/src/node/plugins/wasm.ts:241) reads the .wasm file, calls WebAssembly.compile with Vite's wasm-compiled-options (js-string builtins), then enumerates Module.imports/exports to generate glue code. Any failure — corrupt bytes, unsupported proposal, or a compile error — is re-thrown with the original as `cause` and the file path in the message.
Source
Thrown at packages/vite/src/node/plugins/wasm.ts:263
const importMap = new Map<string, WasmName[]>()
for (const item of WebAssembly.Module.imports(wasmModule)) {
if (wasmReservedModules.has(item.module)) continue
let names = importMap.get(item.module)
if (!names) importMap.set(item.module, (names = []))
names.push({ name: item.name, isGlobal: item.kind === 'global' })
}
const imports = [...importMap].map(([from, names]) => ({ from, names }))
let hasGlobalExport = false
const exports = WebAssembly.Module.exports(wasmModule).map((item) => {
const isGlobal = item.kind === 'global'
if (isGlobal) hasGlobalExport = true
return { name: item.name, isGlobal }
})
return { imports, exports, hasGlobalExport }
} catch (e) {
throw new Error(
`Failed to parse WASM file "${wasmFilePath}": ${(e as Error).message}`,
{ cause: e },
)
}
}
// Instantiates the wasm module and re-exports its exports verbatim. Globals stay
// WebAssembly.Global objects so wasm-to-wasm global imports get the live cell.
function generateInstanceGlue(
wasmInfo: WasmInfo,
names: { initWasm: string; wasmUrl: string },
): string {
const importStatements: string[] = []
const importObject: SimpleObject = wasmInfo.imports.map(
({ from, names: importNames }, i) => {
const value: SimpleObject = []
const globals = importNames.filter((n) => n.isGlobal)
const others = importNames.filter((n) => !n.isGlobal)View on GitHub (pinned to 89620f09af)
Solutions
- Re-build/re-download the .wasm so its bytes are complete and valid; verify with `node -e "WebAssembly.compile(require('fs').readFileSync('x.wasm'))"`.
- Use a Node version that supports the wasm proposals the module was compiled with (check the release that introduced js-string builtins / the proposal in question).
- Confirm the file is actually WebAssembly (`file x.wasm` / check magic bytes \0asm) and that Vite resolves the path you expect.
- If you do not need Vite's glue generation, import the wasm via ?init and instantiate it manually so parseWasm is bypassed.
Example fix
// before: direct import triggers parseWasm and fails on an old Node import wasm from './asset.wasm' // after: validate/upgrade the toolchain, then keep the import // node --version # upgrade to a release with the needed proposal // wasm-pack build --target web import wasm from './asset.wasm'
Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'node:fs'
function wasmLooksValid(file: string): boolean {
const b = readFileSync(file)
return b.length >= 8 && b[0] === 0x00 && b[1] === 0x61 && b[2] === 0x73 && b[3] === 0x6d
}
if (!wasmLooksValid('asset.wasm')) throw new Error('not a valid wasm file') Type guard
function isWasmMagic(bytes: Uint8Array): boolean {
return bytes[0] === 0x00 && bytes[1] === 0x61 && bytes[2] === 0x73 && bytes[3] === 0x6d
} Try / catch
try {
await import('./asset.wasm')
} catch (e) {
if (/Failed to parse WASM file/.test((e as Error).message)) {
// rebuild wasm artifact / upgrade Node, then retry build
}
throw e
} Prevention
- Validate wasm magic bytes before importing in CI.
- Pin the toolchain (wasm-pack/ emscripten) and Node version that together produce supported proposals.
- Treat .wasm as a build artifact: rebuild on toolchain upgrades rather than committing stale binaries.
When it happens
Trigger: Importing a .wasm that is truncated/corrupt; a wasm built with a proposal your host Node version does not support; a non-wasm file accidentally named .wasm; a wasm whose imports reference modules the engine rejects during Module.imports inspection.
Common situations: Bumping @vitejs/plugin-wasm or the toolchain that emits wasm (wasm-pack, emscripten, assemblyscript) to a version using newer proposals; checking out a repo with a stale or partially-downloaded .wasm artifact; case-sensitivity issues on Linux pointing at a non-existent file that fsp.readFile rejects.
Related errors
- Cannot use "sourcemapInterceptor: 'node'" because "process.s
- No environment found
- Either "build.lib.entry" or the top-level "input" option is
- rolldownOptions.input should not be an html file when buildi
- When "build.cssCodeSplit: false" is set, "rolldownOptions.in
AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03).
Data as JSON: /data/errors/95835fce87442db6.json.
Report an issue: GitHub.