wasm-pack
Build tool for compiling Rust to WebAssembly and publishing to npm. Handles wasm-bindgen glue code generation, TypeScript type definitions, and packaging for browser, Node.js, or bundler targets. The standard workflow for Rust → Wasm → npm: write Rust with #[wasm_bindgen] attributes, run wasm-pack build, publish the resulting npm package.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Rust memory safety. Wasm sandbox provides browser-side isolation. npm publishing uses standard npm security model. Open source and auditable.
⚡ Reliability
Best When
You're writing Rust code that needs to run in browsers or Node.js with JavaScript interop via wasm-bindgen and npm distribution.
Avoid When
You don't have Rust code to compile — or you need server-side Wasm execution rather than browser/npm distribution.
Use Cases
- • Compile Rust libraries to WebAssembly npm packages that work in browser, Node.js, or bundled applications
- • Build high-performance compute-heavy functions in Rust (cryptography, image processing, parsing) that run at near-native speed in browsers
- • Create Rust-backed npm packages with TypeScript types auto-generated from wasm-bindgen annotations
- • Integrate existing Rust codebases into JavaScript/TypeScript projects via Wasm without rewriting in JS
- • Publish Wasm-powered npm packages to registries for distribution to web application developers
Not For
- • Non-Rust Wasm compilation — wasm-pack is Rust-specific; use Emscripten for C/C++ or TinyGo for Go
- • Server-side Wasm execution — wasm-pack targets browser/npm distribution; use wasmtime for server-side Wasm
- • Pure JavaScript projects that don't need native performance — the Rust + Wasm toolchain adds significant complexity
Interface
Authentication
No auth for build step. Publishing to npm uses npm credentials (npm login). Publishing to private registries uses their auth.
Pricing
MIT/Apache-2.0 dual licensed. Part of the Rust+Wasm working group. Completely free.
Agent Metadata
Known Gotchas
- ⚠ wasm-pack requires Rust toolchain with wasm32-unknown-unknown target — run 'rustup target add wasm32-unknown-unknown' before first build
- ⚠ Build target (--target web|bundler|nodejs|no-modules) changes generated JS glue code significantly — choose target based on consumption environment
- ⚠ wasm-bindgen version must match wasm-pack's bundled version — mismatch causes cryptic errors; pin versions in Cargo.toml
- ⚠ Large Rust dependency trees can take minutes to compile on first run — CI caching of cargo registry and build artifacts is essential
- ⚠ Generated TypeScript types may need manual refinement for complex Rust types — review .d.ts output before publishing
- ⚠ wasm-pack publish uses npm credentials from .npmrc or npm login — separate authentication from build step in CI
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for wasm-pack.
Scores are editorial opinions as of 2026-03-06.