CLI tool
AssemblyScript/binaryen.js avatar
AssemblyScript/binaryen.js

binaryen.js: Running Binaryen's WebAssembly Toolchain in the Browser and Node.js

A buildbot for browser & Node.js builds of Binaryen, a compiler infrastructure and toolchain library for WebAssembly.

406 stars55 forksJavaScriptApache-2.0

At a glance

What is it?
binaryen.js is a JavaScript port of Binaryen, the WebAssembly compiler infrastructure. It lets you build, optimize, and manipulate Wasm modules with a JS API, and it ships the command-line tools as Node.js binaries.
Who is it for?
Adopt binaryen.js if you need to generate or optimize WebAssembly from JavaScript, especially in a browser environment where native Binaryen binaries are unavailable. If you only need wasm-opt on a server, compare the native Binaryen distribution's deployment and performance with the npm package for your workload.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 58 days ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 14, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • AssemblyScript/binaryen.js406 ★ · +2
Star history
Repository2026-07-312026-11-14
AssemblyScript/binaryen.js404406

2 Stars in the last 106 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What binaryen.js Is For

binaryen.js solves a specific problem: it brings Binaryen, the C++ compiler infrastructure for WebAssembly, to JavaScript. The README describes it as a port to the Web, allowing you to generate WebAssembly using a JavaScript API. That means you can construct a module programmatically, optimize it, and emit binary or text format without leaving the JS ecosystem. The target users are developers building tools that manipulate Wasm at runtime or build time: bundlers, compilers, and anything that needs to transform Wasm in a browser or a Node.js process. If you have ever tried to run wasm-opt in a browser, you know the problem: native binaries do not work there. binaryen.js is the workaround, compiled to WebAssembly itself so it runs anywhere JavaScript runs.

The Module API: Build, Optimize, and Emit

The core of binaryen.js is the Module class. The README gives a concrete example: you create a new binaryen.Module(), add a function with addFunction, and then call myModule.optimize() to optimize. The API is a direct mapping of Binaryen's C++ interface, so it uses references like ExpressionRef and FunctionRef. You construct expressions by chaining calls like myModule.i32.add() and myModule.local.get(). The module object also handles imports, exports, and memory. After building, you can emit the result, using `emitText()` or `emitBinary()`, as the README demonstrates. The API includes parseText to create a module from Binaryen's s-expression format, and readBinary to load from a Uint8Array. This is not a high-level wrapper; it is the full Binaryen API, which means you get fine-grained control but also a steep learning curve if you are new to compiler IR.

Getting It Running: npm and CDN

Installation is straightforward: npm install binaryen. The package also publishes a nightly tag, so npm install binaryen@nightly gets the latest build if there have been changes in the last day. For browser use, the README lists CDN links, for example https://cdn.jsdelivr.net/npm/binaryen@VERSION/index.js. You replace VERSION with a specific release tag, or omit it to get the latest, which the README warns is not recommended for production. The package includes Node.js builds of Binaryen's command-line tools: wasm-shell, wasm-opt, wasm-metadce, wasm2js, wasm-as, wasm-dis, wasm-ctor-eval, wasm-reduce, and wasm-merge. That is a significant convenience: you can run these tools as npm scripts without installing native Binaryen separately.

The Buildbot and the Nightly Release Cycle

The project is described as a buildbot, meaning it is not a hand-maintained port but an automated build that compiles Binaryen to JavaScript. The README mentions it publishes nightly versions once a day if there have been changes. That automation explains the warning in the API section: the Binaryen API is evolving fast, and definitions and documentation provided by the package tend to get out of sync despite our best efforts. It's a bot after all. This is a real trade-off. You get fresh builds with the latest Binaryen features, but you also get the risk that the TypeScript definitions (index.d.ts) lag behind the actual API. The README explicitly asks users to send pull requests to update index.d.ts and README.md to reflect the current API. If you rely on TypeScript types, you may need to check the generated definitions against the actual behavior.

Limitations: API Drift and Feature Support

The most obvious limitation is the API drift just mentioned. The README itself says the definitions and docs 'tend to get out of sync.' That means you cannot trust the type hints or even the README examples to match the installed version. Another limitation is feature support: the README marks several operations with a unicorn emoji, such as atomic memory accesses, exception handling, and reference types. The note says 'Future features might not be supported by all runtimes.' So even if binaryen.js exposes these operations, the resulting Wasm may not run everywhere. Also, the API is low-level. The example shows manual local management: you set a local, get it, and return it. That is verbose compared to higher-level compilers like AssemblyScript itself. If you are generating Wasm from a language, you would not use binaryen.js directly; you would use a front-end that emits the IR.

Alternatives: Native Binaryen and Other Wasm Generators

The natural alternative is the native Binaryen distribution, which you install via a package manager or build from source. The difference is deployment: native binaries run only on the host platform, so you cannot use them in a browser or in a cross-platform npm package without per-platform binaries. binaryen.js trades speed and native performance for portability. Another alternative is to use a JavaScript library that generates Wasm at a higher level, such as wabt.js or the WebAssembly JavaScript API directly. The WebAssembly API lets you instantiate and compile, but it does not offer optimization passes or the rich IR manipulation that Binaryen provides. binaryen.js is the only option in this list that gives you Binaryen's optimizer in a browser. If you need wasm-opt specifically, binaryen.js is the direct answer, but if you just need to compile a simple module, the built-in WebAssembly API may suffice.

Maintenance and License

The project is hosted under the AssemblyScript organization, but the README points to the WebAssembly/binaryen repository as the source. The license is Apache-2.0, which allows commercial use, modification, and distribution, with the usual conditions about retaining copyright notices. Maintenance is automated through the buildbot, but the human maintenance burden falls on the AssemblyScript team and contributors who keep the typings and README current. The last push date is unknown, and no recent releases are listed, which might indicate a lull or just that the buildbot tags releases differently. The README mentions 'previous versions' available via tags, so release tagging is a normal part of the workflow. If you depend on binaryen.js, you should track the nightly builds for fixes, but also pin to a specific version for stability, because the API can change between nightlies.

Editorial conclusion

Adopt binaryen.js if you need to generate or optimize WebAssembly from JavaScript, especially in a browser environment where native Binaryen binaries are unavailable. If you only need wasm-opt on a server, compare the native Binaryen distribution's deployment and performance with the npm package for your workload. Before adopting, verify that the API version matches the Binaryen features you use, since the README warns the definitions can drift. Also check the nightly build for recent fixes if you hit a bug in the stable release.

Frequently asked questions

What is binaryen.js and what does it give me?

It is a browser and Node.js build of Binaryen, the WebAssembly compiler infrastructure, packaged so you can generate WebAssembly through a JavaScript API. The same install also provides Node.js builds of nine Binaryen command line tools, including wasm-opt, wasm-as, wasm-dis, wasm2js, wasm-reduce, and wasm-merge. The package is versioned to upstream, currently 132.0.0.

How do I install binaryen.js?

Run npm install binaryen. If you want the newest build, npm install binaryen@nightly gets the latest nightly, which the buildbot publishes once a day when there have been changes. For a browser without a bundler, three CDN routes are documented, and the guidance is to put a specific version in the path rather than omitting it, which is marked as not recommended in production.

Is the binaryen.js type definition file reliable?

The project says the opposite. The documentation states that the Binaryen API is evolving fast and that definitions and documentation in the package tend to get out of sync, and it asks anyone who spots an issue to send a pull request updating the declaration file and the readme to match the current upstream API. The test suite type-checks the declaration file under strict mode but does not compare it to upstream.

Does binaryen.js support the newer WebAssembly reference types?

The type list includes v128, funcref, externref, anyref, eqref, i31ref, structref, and stringref, and marks them as future features with a note that they might not be supported by all runtimes. A module built against one of them can therefore be well formed and still be rejected by a given runtime.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/assemblyscript-binaryen-js.svg)](https://hysenlabs.com/projects/assemblyscript-binaryen-js)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/assemblyscript-binaryen-js.svg)](https://hysenlabs.com/projects/assemblyscript-binaryen-js)

Was this useful?