Registry / http-networking / rollup-plugin-rust

rollup-plugin-rust

JSON →
library1.2.0jsnpmunverified

A Rollup plugin that compiles Rust code into WebAssembly modules, enabling seamless interop between Rust and JavaScript projects. Version 1.2.0, currently in active development with no recent updates. Requires Node >= 8.9.0, Rollup >= 0.64.0, and Rust nightly with wasm32-unknown-unknown target. Supports various export modes (WebAssembly.Instance, WebAssembly.Module, buffer), release/debug builds, and custom include/exclude patterns. Differentiates from other WASM plugins by focusing specifically on Rust compilation via the rustc compiler, offering tight integration with Rollup's build pipeline.

npm install rollup-plugin-rust
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-RUST
R
rollup-plugin-rust
http-networkingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
import rust from 'rollup-plugin-rust'
const rust = require('rollup-plugin-rust').default
The plugin exports a default function. Use ESM import syntax.
rust (default import with options)
import rust from 'rollup-plugin-rust'; rust({ release: false })
import { rust } from 'rollup-plugin-rust'
The default export is a function that takes an options object.
RustOptions (type)
import type { RustOptions } from 'rollup-plugin-rust'
TypeScript definitions are shipped; use type import for options interface.
RustPlugin (type alias)
import type { RustPlugin } from 'rollup-plugin-rust'
The plugin function returns a Rollup plugin object; this type may be useful for generic typing.

Shows a minimal Rollup configuration using the plugin to compile Rust to WASM, and how to import and use the WASM module in JavaScript.

// rollup.config.js import rust from 'rollup-plugin-rust'; export default { input: 'src/main.js', output: { file: 'dist/bundle.js', format: 'esm' }, plugins: [rust({ release: true })] }; // lib.rs // #[no_mangle] // pub fn add(a: i32, b: i32) -> i32 { // a + b // } // src/main.js import wasm from './lib.rs'; export async function increment(a) { const { instance } = await wasm; return instance.exports.add(1, a); }
Debug
Known issues
breakingRequires Rust nightly channel to compile WASM targets.
fix
Use 'rustup default nightly' and install wasm32-unknown-unknown target.
affects: >=1.0.0
gotchaOnly supports wasm-related targets (wasm32-unknown-unknown, wasm32-unknown-emscripten).
fix
Set 'target' option to a valid WASM target; other targets will fail compilation.
affects: >=1.0.0
gotchaThe plugin compiles Rust code via rustc, which can be slow on first run due to crate compilation.
fix
Consider using caching or incremental compilation in Rust (nightly feature).
affects: >=1.0.0
deprecatedNode v8 is EOL; plugin may not work on newer Node versions due to dependencies.
fix
Upgrade Node to v12 or later and test compatibility; consider using an alternative plugin with newer maintenance.
affects: >=1.0.0
gotchaImport path must point to a .rs file; the plugin resolves Rust files by extension.
fix
Use './lib.rs' (with extension) in import statements.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Could not resolve 'lib.rs' from 'src/main.js'
The plugin's include pattern does not cover the Rust file, or the file path is incorrect.
fix
Ensure 'lib.rs' exists at the specified path and that 'include' option in plugin configuration matches the file.
Error: wasm32-unknown-unknown target is not installed
The required Rust compilation target is missing.
fix
Run 'rustup target add wasm32-unknown-unknown' and ensure Rust is on nightly channel.
TypeError: rust is not a function
Improper import; using CommonJS require without .default or importing as named export.
fix
Use 'import rust from "rollup-plugin-rust"' or 'const rust = require("rollup-plugin-rust").default'.
Error: rollup-plugin-rust: No Rust source file provided
The plugin did not match any Rust files in the Rollup build.
fix
Verify that your import statement points to a .rs file and the file exists.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
rollup-plugin-rust — npm install rollup-plugin-rust · libregistry