{"id":22921,"library":"vite-plugin-wasm-pack","title":"vite-plugin-wasm-pack","description":"Vite plugin (v0.1.12) that integrates Rust WebAssembly crates built with wasm-pack into Vite projects. It automatically serves local wasm-pack crates and supports npm-published wasm-pack packages (target web). The plugin wires up Vite's dev server and build pipeline to handle .wasm files and JavaScript glue code. It requires wasm-pack to be installed separately and the crate must be built beforehand. Compared to alternatives like vite-plugin-wasm, this plugin is specifically designed for wasm-pack output and offers simpler configuration for local crates.","status":"active","version":"0.1.12","language":"javascript","source_language":"en","source_url":"https://github.com/nshen/vite-plugin-wasm-pack","tags":["javascript","wasm-pack","wasm-bindgen","vite-plugin","webassembly","wasm","rust","vite","cargo","typescript"],"install":[{"cmd":"npm install vite-plugin-wasm-pack","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-wasm-pack","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-wasm-pack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: works as a Vite plugin","package":"vite","optional":false}],"imports":[{"note":"ESM default export. CommonJS require may work but is not recommended.","wrong":"const wasmPack = require('vite-plugin-wasm-pack')","symbol":"default (wasmPack)","correct":"import wasmPack from 'vite-plugin-wasm-pack'"},{"note":"The plugin is a default export, not a named export.","wrong":"import { wasmPack } from 'vite-plugin-wasm-pack'","symbol":"vite config usage","correct":"import wasmPack from 'vite-plugin-wasm-pack';\nimport { defineConfig } from 'vite';\nexport default defineConfig({ plugins: [wasmPack('./crate')] })"},{"note":"Package ships TypeScript types. No separate type import needed.","wrong":null,"symbol":"TypeScript types","correct":"import wasmPack from 'vite-plugin-wasm-pack'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport wasmPack from 'vite-plugin-wasm-pack';\n\nexport default defineConfig({\n  plugins: [wasmPack('./my-crate')]\n});\n\n// After building the crate with:\n// wasm-pack build ./my-crate --target web\n\n// In your frontend code:\nimport init, { greet } from './my-crate';\nasync function main() {\n  await init();\n  greet('World');\n}\nmain();","lang":"typescript","description":"Shows how to configure Vite with a local wasm-pack crate and use its exports."},"warnings":[{"fix":"Run 'wasm-pack build ./my-crate --target web' before 'vite' or 'vite build'.","message":"Crate must be built manually with wasm-pack before starting the dev server.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Rebuild the package with '--target web' or use a different plugin.","message":"Only packages built with --target web are supported. npm packages built with other targets will not work.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Clear Vite cache by deleting node_modules/.vite or restarting the dev server.","message":"Vite may cache your wasm module. After modifying Rust code, the old module might be served.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'wasm-pack build ./my-crate --target web' and ensure the path matches.","cause":"The wasm-pack output has not been built or the path is incorrect.","error":"Cannot find module './my-crate' or its corresponding type declarations."},{"fix":"Disable source maps in Vite config or ignore the error; it is non-blocking.","cause":"The wasm-pack generated source map may be incomplete or missing.","error":"Failed to parse source map: .../my-crate/pkg/my_crate.js"},{"fix":"Provide an absolute or relative path to the crate directory containing Cargo.toml.","cause":"The crate path passed to wasmPack() is incorrect or does not contain a Cargo.toml.","error":"[vite] Internal server error: wasm-pack plugin: crate not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}