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.

npm install binaryen
INSTALL
IMPORT
SIG · BINARYEN
B
binaryen
datajavascriptv129.0.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.

Binaryen
import Binaryen from 'binaryen'
Default export in ESM is a namespace object; call Binaryen.ready() before use (Async).
Module
import Binaryen from 'binaryen'; const mod = new Binaryen.Module()
Module is a class on the default export; not a named export.
readBinary (via Binaryen)
import Binaryen from 'binaryen'; const wasmBuffer = Binaryen.readBinary(new Uint8Array([...]))
readBinary is attached to the default export, not imported standalone.

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 issues
gotchaBinaryen.ready() must be called and awaited before any other API calls; failure leads to 'Binaryen is not initialized' errors.
fix
Always await Binaryen.ready() at top of your script.
affects: >=0.0.0
gotchaThe Binaryen npm package is ESM-only starting from version 100.0.0; CommonJS require() will fail.
fix
Use import syntax or upgrade to Node >=12.22 or use dynamic import().
affects: >=100.0.0
gotchaThe API is synchronous but built on WebAssembly; thread-blocking operations may impact performance on the main thread.
fix
Consider offloading to a Web Worker or use Async variants if available (currently no async API, but Binaryen.ready is async).
affects: >=0.0.0
gotchaTypeScript types are provided but may lag behind the Native API; some methods may be missing or incorrectly typed.
fix
Check the type definition file (.d.ts) for completeness; use 'as any' if needed.
affects: <110.0.0
Errors
Common errors & fixes
TypeError: Binaryen.Module is not a constructor
Forgetting to await Binaryen.ready() before using Binaryen.Module.
fix
Add 'await Binaryen.ready();' before any other Binaryen calls.
Error: Binaryen is not initialized
Binaryen.ready() not called or not awaited.
fix
Ensure Binaryen.ready() is called and awaited at the start of your async function.
require() of ES Module ... not supported
Using CommonJS require() on an ESM-only package (version >=100).
fix
Switch to 'import Binaryen from 'binaryen'' and use an ESM-compatible setup.
Module "..." has been added to an invalid position
Incorrect order of module construction (e.g., adding function export before function).
fix
Ensure all function types, functions, and imports are added before exports.
Upgrade
Version history
129.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
binaryen — npm install binaryen · libregistry