{"id":22922,"library":"vite-plugin-wasm","title":"Vite Plugin WASM","description":"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.","status":"active","version":"3.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/Menci/vite-plugin-wasm","tags":["javascript","vite","plugin","wasm","webassembly","wasm-pack","es-modules","modules","typescript"],"install":[{"cmd":"npm install vite-plugin-wasm","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-wasm","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-wasm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin works with Vite 2.x to 8.x","package":"vite","optional":false},{"reason":"recommended companion plugin for non-esnext build targets to handle top-level await in WASM modules","package":"vite-plugin-top-level-await","optional":true}],"imports":[{"note":"ESM-only package; use dynamic import for CommonJS","wrong":"const wasm = require('vite-plugin-wasm')","symbol":"default","correct":"import wasm from 'vite-plugin-wasm'"},{"note":"Default export, not named. Plugin function is the default export.","wrong":"import { wasm } from 'vite-plugin-wasm'","symbol":"wasm","correct":"import wasm from 'vite-plugin-wasm'"},{"note":"TypeScript only; use type import to avoid runtime issues","wrong":"import { VitePluginWasmOptions } from 'vite-plugin-wasm'","symbol":"VitePluginWasmOptions","correct":"import type { VitePluginWasmOptions } from 'vite-plugin-wasm'"}],"quickstart":{"code":"import wasm from 'vite-plugin-wasm';\nimport topLevelAwait from 'vite-plugin-top-level-await';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n  plugins: [\n    wasm(),\n    topLevelAwait()\n  ]\n});","lang":"typescript","description":"Shows basic setup with required companion plugin for top-level await support."},"warnings":[{"fix":"Use asterisk import (import * as wasmModule from './module.wasm') with type assertion.","message":"TypeScript typing is broken: importing .wasm files still gets Vite's built-in typing, not the plugin's custom module declaration.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Vite to >=3.0.3 or plugin to >=3.1.0, or exclude the offending package from optimizeDeps.","message":"ESBuild errors with .wasm files in Vite < 3.0.3: 'No loader is configured for \".wasm\" files' appears when importing WASM from node_modules.","severity":"breaking","affected_versions":"<3.1.0"},{"fix":"Add wasm() and topLevelAwait() to worker.plugins in Vite config, and don't set worker.format to 'es' for Firefox support.","message":"Web Workers require manual addition of plugin to worker.plugins.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Remove worker.format configuration; rely on vite-plugin-top-level-await for compatibility.","message":"worker.format: 'es' support removed in vite-plugin-top-level-await >= 1.3.0; leaving format default (module) is fine.","severity":"deprecated","affected_versions":">=1.3.0 of vite-plugin-top-level-await"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Upgrade Vite to >=3.0.3 or plugin to >=3.1.0, or add 'optimizeDeps.exclude: [\"somepackage\"]' to vite.config.","cause":"Vite version below 3.0.3 or plugin version below 3.1.0 does not handle WASM imports from node_modules.","error":"No loader is configured for \".wasm\" files: node_modules/somepackage/somefile.wasm"},{"fix":"Add topLevelAwait() plugin to Vite config.","cause":"Omitting vite-plugin-top-level-await when build.target is not 'esnext'.","error":"Top-level await is not available in the configured target environment"},{"fix":"Use import or dynamic import() instead of require().","cause":"Package is ESM-only; require() is not supported.","error":"Cannot find module 'vite-plugin-wasm' when using require()"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}