Registry / devops / wat-compiler

wat-compiler

JSON →
library1.1.1jsnpmunverified

wat-compiler is a zero-dependency JavaScript library that compiles WebAssembly Text Format (WAT) source code into binary WebAssembly modules (Uint8Array). It provides a simple functional API with optional performance metrics. v1.1.1 is the latest stable version; the library is lightweight, has no external runtime dependencies, and ships TypeScript definitions. Unlike full WAT toolchains (wabt, wast2wasm), it is designed for in-browser or Node.js use with minimal overhead.

npm install wat-compiler
INSTALL
IMPORT
SIG · WAT-COMPILER
W
wat-compiler
devopsjavascriptv1.1.1
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.

default
import compile from 'wat-compiler'
const compile = require('wat-compiler')
The default export is the compile function. CommonJS require is not supported; ESM only.
make
import compile from 'wat-compiler'
import { make } from 'wat-compiler'
The default export is named `compile` in the source (originally `make`), but is exported as default. Named export `make` does not exist.
TypeScript types
import compile from 'wat-compiler'
import type { CompileOptions } from 'wat-compiler'
The library ships types, but the options type is not exported as a named type. Use the default import for both value and type inference.

Demonstrates compiling a simple WAT module to binary, then instantiating WebAssembly.

import compile from 'wat-compiler' const wat = `(module (func (export "answer") (result i32) i32.const 42 ) )` const binary = compile(wat) const mod = new WebAssembly.Module(binary) const instance = new WebAssembly.Instance(mod) console.log(instance.exports.answer()) // 42 // With metrics enabled const binary2 = compile(wat, { metrics: true }) console.log(binary2)
Debug
Known issues
gotchaError when compiling malformed WAT: SyntaxError: Unexpected token
fix
Ensure WAT syntax is valid. Use a tool like `wat2wasm` for debugging.
affects: >=1.0.0
breakingDefault export changed from `make` to `compile` in v1.0.0
fix
Use `import compile from 'wat-compiler'` instead of `import { make } from 'wat-compiler'`.
affects: >=1.0.0
deprecatedThe `options.metrics` flag may be removed in future versions
fix
For performance measurement, use external tools like `console.time` instead.
affects: >=1.0.0
gotchaCommonJS `require('wat-compiler')` returns undefined
fix
Switch to ESM import syntax. The package is ESM-only.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/wat-compiler/index.js from /path/to/script.js not supported.
Using CommonJS require to import an ESM-only module.
fix
Use `import compile from 'wat-compiler'` in an ESM context, or use dynamic import: `const compile = (await import('wat-compiler')).default`.
SyntaxError: Unexpected token
Supplied WAT code is malformed or missing required module structure.
fix
Validate WAT syntax with `wat2wasm` or check the WebAssembly specification. Ensure the module has a `(module ...)` wrapper.
TypeError: compile is not a function
Incorrect import pattern (e.g., named import `{ watCompile }` or default import with wrong name).
fix
Use `import compile from 'wat-compiler'` (default import).
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
wat-compiler — npm install wat-compiler · libregistry