Registry / web-framework / vite-plugin-wasm

vite-plugin-wasm

JSON →
library3.6.0jsnpmunverified

Adds WebAssembly ESM integration (aka Webpack's asyncWebAssembly) to Vite and supports wasm-pack generated modules. Current stable version is 3.6.0, compatible with Vite 2.x through 8.x. Releases follow regular cadence with breaking changes aligned with Vite major versions. Key differentiators: enables importing .wasm files as ES modules, handles wasm-pack output, and works in Web Workers. Requires vite-plugin-top-level-await for browser targets below esnext. Ships TypeScript declarations.

npm install vite-plugin-wasm
INSTALL
IMPORT
SIG · VITE-PLUGIN-WASM
V
vite-plugin-wasm
web-frameworkjavascriptv3.6.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import wasm from 'vite-plugin-wasm'
✗ const wasm = require('vite-plugin-wasm')
ESM-only package; use dynamic import for CommonJS
wasm
✓ import wasm from 'vite-plugin-wasm'
✗ import { wasm } from 'vite-plugin-wasm'
Default export, not named. Plugin function is the default export.
VitePluginWasmOptions
✓ import type { VitePluginWasmOptions } from 'vite-plugin-wasm'
✗ import { VitePluginWasmOptions } from 'vite-plugin-wasm'
TypeScript only; use type import to avoid runtime issues

Shows basic setup with required companion plugin for top-level await support.

import wasm from 'vite-plugin-wasm'; import topLevelAwait from 'vite-plugin-top-level-await'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ wasm(), topLevelAwait() ] });
Debug
Known issues
gotchaTypeScript typing is broken: importing .wasm files still gets Vite's built-in typing, not the plugin's custom module declaration.
fix
Use asterisk import (import * as wasmModule from './module.wasm') with type assertion.
affects: >=0.0.0
breakingESBuild errors with .wasm files in Vite < 3.0.3: 'No loader is configured for ".wasm" files' appears when importing WASM from node_modules.
fix
Upgrade Vite to >=3.0.3 or plugin to >=3.1.0, or exclude the offending package from optimizeDeps.
affects: <3.1.0
gotchaWeb Workers require manual addition of plugin to worker.plugins.
fix
Add wasm() and topLevelAwait() to worker.plugins in Vite config, and don't set worker.format to 'es' for Firefox support.
affects: >=0.0.0
deprecatedworker.format: 'es' support removed in vite-plugin-top-level-await >= 1.3.0; leaving format default (module) is fine.
fix
Remove worker.format configuration; rely on vite-plugin-top-level-await for compatibility.
affects: >=1.3.0 of vite-plugin-top-level-await
Errors
Common errors & fixes
No loader is configured for ".wasm" files: node_modules/somepackage/somefile.wasm
Vite version below 3.0.3 or plugin version below 3.1.0 does not handle WASM imports from node_modules.
fix
Upgrade Vite to >=3.0.3 or plugin to >=3.1.0, or add 'optimizeDeps.exclude: ["somepackage"]' to vite.config.
Top-level await is not available in the configured target environment
Omitting vite-plugin-top-level-await when build.target is not 'esnext'.
fix
Add topLevelAwait() plugin to Vite config.
Cannot find module 'vite-plugin-wasm' when using require()
Package is ESM-only; require() is not supported.
fix
Use import or dynamic import() instead of require().
Upgrade
Version history
3.6.0latest on npm
Audit
Dependencies
viterequiredpeer dependency; plugin works with Vite 2.x to 8.x
vite-plugin-top-level-awaitoptionalrecommended companion plugin for non-esnext build targets to handle top-level await in WASM modules
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
vite-plugin-wasm — npm install vite-plugin-wasm · libregistry