Registry / devops / esbuild-plugin-wasm-pack

esbuild-plugin-wasm-pack

JSON →
library1.1.0jsnpmunverified

esbuild-plugin-wasm-pack is an esbuild plugin that runs wasm-pack before each build to compile Rust/Wasm crates. Version 1.1.0 is the latest stable release. It integrates esbuild with the wasm-pack toolchain, automatically generating WebAssembly modules during the bundling process. Key differentiators include seamless integration with esbuild's plugin system, TypeScript support via generated .d.ts files, and full configuration parity with wasm-pack build arguments. It requires Node.js >=0.10.0, esbuild >=0.11.15, Rust/Cargo, and wasm-pack to be installed. The plugin is actively maintained on GitHub and distributed via npm.

npm install esbuild-plugin-wasm-pack
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-WAS
E
esbuild-plugin-wasm-pack
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default (wasmpack)
import wasmpack from 'esbuild-plugin-wasm-pack'
const wasmpack = require('esbuild-plugin-wasm-pack')
The plugin is a CommonJS module that exports a function; default import is safe in ES or CJS contexts. Use require if not using ESM.
type imports
import type { WasmPackOptions } from 'esbuild-plugin-wasm-pack'
Types are shipped and can be imported from the package directly.

Demonstrates how to use esbuild-plugin-wasm-pack to build a Rust WebAssembly crate during an esbuild build.

import esbuild from 'esbuild'; import wasmpack from 'esbuild-plugin-wasm-pack'; await esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, outfile: 'dist/bundle.js', plugins: [ wasmpack({ path: './rust-crate', // path to your Rust crate target: 'bundler', profile: 'release', logLevel: 'warn', }), ], });
Debug
Known issues
gotchawasm-pack must be installed and available in PATH, otherwise the plugin will fail silently or throw an obscure error.
fix
Ensure wasm-pack is installed globally (e.g., cargo install wasm-pack) and verify with 'which wasm-pack' or set WASM_PACK_PATH environment variable.
affects: >=1.0.0
gotchaThe plugin runs wasm-pack synchronously via execSync, which can block the event loop during builds.
fix
Consider using wasm-pack programmatically or running it as a separate build step for large crates.
affects: >=1.0.0
breakingAs of version 1.0.0, the plugin changed from a class-based API to a function-based API. Users upgrading from 0.x may need to adjust their usage.
fix
Use the functional import: import wasmpack from 'esbuild-plugin-wasm-pack' and call it as a function with options.
affects: >=1.0.0
deprecatedThe 'node' engine requirement is >=0.10.0, which is extremely outdated. There is a risk of using unsupported Node.js versions.
fix
Use Node.js >=12 (or current LTS) to ensure compatibility with esbuild and modern JavaScript features.
affects: >=1.0.0
gotchaThe plugin does not validate that the specified 'path' contains a valid Cargo.toml. Misconfiguration leads to confusing errors.
fix
Double-check the 'path' option points to a directory with a Cargo.toml file.
affects: >=1.0.0
Errors
Common errors & fixes
Error: spawn wasm-pack ENOENT
wasm-pack is not installed or not in PATH.
fix
Install wasm-pack globally: 'cargo install wasm-pack'. Alternatively, set the 'wasmPackPath' option or WASM_PACK_PATH environment variable to the executable's path.
TypeError: wasmpack is not a function
Incorrect import style; the plugin exports a function, not an object.
fix
Use 'import wasmpack from "esbuild-plugin-wasm-pack"' (default import) or 'const wasmpack = require("esbuild-plugin-wasm-pack")'. Do not destructure.
wasm-pack build failed with exit code 101
wasm-pack encountered an error while building the Rust crate.
fix
Check the Rust crate for compilation errors. Ensure all dependencies are present. Run 'wasm-pack build' in the crate directory to see detailed output.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency; the plugin hooks into esbuild's build process.
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-wasm-pack — npm install esbuild-plugin-wasm-pack · libregistry