{"id":22207,"library":"rollup-plugin-rust","title":"rollup-plugin-rust","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/DrSensor/rollup-plugin-rust","tags":["javascript","rollup-plugin","rust","webassembly","typescript"],"install":[{"cmd":"npm install rollup-plugin-rust","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-rust","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-rust","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The plugin exports a default function. Use ESM import syntax.","wrong":"const rust = require('rollup-plugin-rust').default","symbol":"default","correct":"import rust from 'rollup-plugin-rust'"},{"note":"The default export is a function that takes an options object.","wrong":"import { rust } from 'rollup-plugin-rust'","symbol":"rust (default import with options)","correct":"import rust from 'rollup-plugin-rust'; rust({ release: false })"},{"note":"TypeScript definitions are shipped; use type import for options interface.","wrong":"","symbol":"RustOptions (type)","correct":"import type { RustOptions } from 'rollup-plugin-rust'"},{"note":"The plugin function returns a Rollup plugin object; this type may be useful for generic typing.","wrong":"","symbol":"RustPlugin (type alias)","correct":"import type { RustPlugin } from 'rollup-plugin-rust'"}],"quickstart":{"code":"// rollup.config.js\nimport rust from 'rollup-plugin-rust';\n\nexport default {\n  input: 'src/main.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'esm'\n  },\n  plugins: [rust({ release: true })]\n};\n\n// lib.rs\n// #[no_mangle]\n// pub fn add(a: i32, b: i32) -> i32 {\n//     a + b\n// }\n\n// src/main.js\nimport wasm from './lib.rs';\n\nexport async function increment(a) {\n  const { instance } = await wasm;\n  return instance.exports.add(1, a);\n}","lang":"javascript","description":"Shows a minimal Rollup configuration using the plugin to compile Rust to WASM, and how to import and use the WASM module in JavaScript."},"warnings":[{"fix":"Use 'rustup default nightly' and install wasm32-unknown-unknown target.","message":"Requires Rust nightly channel to compile WASM targets.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Set 'target' option to a valid WASM target; other targets will fail compilation.","message":"Only supports wasm-related targets (wasm32-unknown-unknown, wasm32-unknown-emscripten).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using caching or incremental compilation in Rust (nightly feature).","message":"The plugin compiles Rust code via rustc, which can be slow on first run due to crate compilation.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node to v12 or later and test compatibility; consider using an alternative plugin with newer maintenance.","message":"Node v8 is EOL; plugin may not work on newer Node versions due to dependencies.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use './lib.rs' (with extension) in import statements.","message":"Import path must point to a .rs file; the plugin resolves Rust files by extension.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure 'lib.rs' exists at the specified path and that 'include' option in plugin configuration matches the file.","cause":"The plugin's include pattern does not cover the Rust file, or the file path is incorrect.","error":"Error: Could not resolve 'lib.rs' from 'src/main.js'"},{"fix":"Run 'rustup target add wasm32-unknown-unknown' and ensure Rust is on nightly channel.","cause":"The required Rust compilation target is missing.","error":"Error: wasm32-unknown-unknown target is not installed"},{"fix":"Use 'import rust from \"rollup-plugin-rust\"' or 'const rust = require(\"rollup-plugin-rust\").default'.","cause":"Improper import; using CommonJS require without .default or importing as named export.","error":"TypeError: rust is not a function"},{"fix":"Verify that your import statement points to a .rs file and the file exists.","cause":"The plugin did not match any Rust files in the Rollup build.","error":"Error: rollup-plugin-rust: No Rust source file provided"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}