{"id":26419,"library":"sourceror","title":"Sourceror","description":"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.","status":"active","version":"0.8.5","language":"javascript","source_language":"en","source_url":"https://github.com/source-academy/sourceror","tags":["javascript","typescript"],"install":[{"cmd":"npm install sourceror","lang":"bash","label":"npm"},{"cmd":"yarn add sourceror","lang":"bash","label":"yarn"},{"cmd":"pnpm add sourceror","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the runtime and source language definitions for the Source language","package":"js-slang","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require will fail.","wrong":"const sourceror = require('sourceror')","symbol":"sourceror","correct":"import sourceror from 'sourceror'"},{"note":"Default export is the compile function.","wrong":null,"symbol":"compile","correct":"import { compile } from 'sourceror'"},{"note":"TypeScript type for Source language variants.","wrong":null,"symbol":"sourceLanguage","correct":"import { sourceLanguage } from 'sourceror'"}],"quickstart":{"code":"import sourceror from 'sourceror';\nimport { parse } from 'js-slang';\n\nconst code = `\nfunction add(x, y) {\n  return x + y;\n}\nadd(1, 2);\n`;\n\nconst ast = parse(code, { language: 'source' });\nconst wasmModule = await sourceror(ast);\nconsole.log(wasmModule); // WebAssembly.Module instance","lang":"typescript","description":"Compiles a simple Source function to a WebAssembly module using the default export."},"warnings":[{"fix":"Run node --experimental-wasm-modules your-script.js","message":"CLI requires Node flag --experimental-wasm-modules","severity":"gotcha","affected_versions":">=0.0"},{"fix":"Use import syntax instead of require()","message":"Package is ESM-only; no CommonJS support","severity":"breaking","affected_versions":">=0.8"},{"fix":"Update to 0.8+ and use the default export as a function","message":"Older versions used a different API (e.g., sourceror as object with compile method)","severity":"deprecated","affected_versions":"<0.8"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import instead of require(), or set { \"type\": \"module\" } in package.json","cause":"Using CommonJS require() on an ESM-only package","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module"},{"fix":"Ensure your project is ESM by adding \"type\": \"module\" in package.json","cause":"Mixing module systems in the same project","error":"SyntaxError: The requested module 'sourceror' is expected to be of type CommonJS but is ESM"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}