Registry / data / binaryen

binaryen

JSON →
library129.0.0jsnpmunverified

Binaryen.js provides prebuilt browser and Node.js binaries of Binaryen, a compiler infrastructure and toolchain library for WebAssembly. Version 129.0.0 is the latest stable release; the project follows Binaryen releases closely. It optimizes Wasm modules, performs transformations (e.g., inlining, dead code elimination), and validates/parses Wasm. Key differentiators: it works entirely in JavaScript with no native dependencies, making it suitable for web build pipelines, and it supports both ESM and CommonJS. Compared to wasm-opt CLI, it enables programmatic Wasm optimization in Node.js or browser bundlers.

datadevops
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 export in ESM is a namespace object; call Binaryen.ready() before use (Async).

import Binaryen from 'binaryen'

Module is a class on the default export; not a named export.

import Binaryen from 'binaryen'; const mod = new Binaryen.Module()

readBinary is attached to the default export, not imported standalone.

import Binaryen from 'binaryen'; const wasmBuffer = Binaryen.readBinary(new Uint8Array([...]))

Creates a simple Wasm module with an 'add' function, validates, and emits binary.

import Binaryen from 'binaryen'; async function main() { await Binaryen.ready(); // ensure runtime is initialized const module = new Binaryen.Module(); const funcType = module.addFunctionType('i32', Binaryen.i32, []); const func = module.addFunction('add', funcType, [], [ module.local.get(0, Binaryen.i32), module.local.get(1, Binaryen.i32), module.i32.add() ]); module.addFunctionExport('add', 'add'); module.validate(); const binary = module.emitBinary(); console.log('Wasm binary size:', binary.length, 'bytes'); } main();
Debug
Known footguns
gotchaBinaryen.ready() must be called and awaited before any other API calls; failure leads to 'Binaryen is not initialized' errors.
gotchaThe Binaryen npm package is ESM-only starting from version 100.0.0; CommonJS require() will fail.
gotchaThe API is synchronous but built on WebAssembly; thread-blocking operations may impact performance on the main thread.
gotchaTypeScript types are provided but may lag behind the Native API; some methods may be missing or incorrectly typed.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
16 hits · last 30 days
ahrefsbot
4
gptbot
3
bytedance
3
claudebot
3
Resources