Sourceror
raw JSON → 0.8.5 verified Fri May 01 auth: no javascript
Sourceror is a compiler toolchain that transforms a subset of JavaScript (Source) into WebAssembly. The current stable version is 0.8.5, with a moderate release cadence of irregular updates. Key differentiators: it targets educational use via the js-slang runtime, ships TypeScript types, and requires Node's experimental WASM modules for CLI usage.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module ↓
cause Using CommonJS require() on an ESM-only package
fix
Use import instead of require(), or set { "type": "module" } in package.json
error SyntaxError: The requested module 'sourceror' is expected to be of type CommonJS but is ESM ↓
cause Mixing module systems in the same project
fix
Ensure your project is ESM by adding "type": "module" in package.json
Warnings
gotcha CLI requires Node flag --experimental-wasm-modules ↓
fix Run node --experimental-wasm-modules your-script.js
breaking Package is ESM-only; no CommonJS support ↓
fix Use import syntax instead of require()
deprecated Older versions used a different API (e.g., sourceror as object with compile method) ↓
fix Update to 0.8+ and use the default export as a function
Install
npm install sourceror yarn add sourceror pnpm add sourceror Imports
- sourceror wrong
const sourceror = require('sourceror')correctimport sourceror from 'sourceror' - compile
import { compile } from 'sourceror' - sourceLanguage
import { sourceLanguage } from 'sourceror'
Quickstart
import sourceror from 'sourceror';
import { parse } from 'js-slang';
const code = `
function add(x, y) {
return x + y;
}
add(1, 2);
`;
const ast = parse(code, { language: 'source' });
const wasmModule = await sourceror(ast);
console.log(wasmModule); // WebAssembly.Module instance