{"id":18083,"library":"wasmbuilder","title":"WasmBuilder","description":"WasmBuilder is a JavaScript package initially released in 2019, designed for the manual construction of WebAssembly (WASM) modules. It operates at an extremely low level, requiring developers to specify WASM bytecode directly in hexadecimal format. The library provides a programmatic interface to define functions, memory, and tables, offering fine-grained control over the WASM module's internal structure without relying on higher-level language compilation. Its last recorded update was in October 2019, with version 0.0.16, indicating the project is no longer actively maintained. This low-level approach differentiates it from compilers and makes it suitable primarily for educational purposes, deep dives into WASM internals, or highly specialized niche use cases requiring byte-level WASM manipulation.","status":"abandoned","version":"0.0.16","language":"javascript","source_language":"en","source_url":"https://github.com/iden3/wasmbuilder","tags":["javascript","wasm","script","generator"],"install":[{"cmd":"npm install wasmbuilder","lang":"bash","label":"npm"},{"cmd":"yarn add wasmbuilder","lang":"bash","label":"yarn"},{"cmd":"pnpm add wasmbuilder","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses CommonJS `require` syntax as it was last updated in 2019. Direct ESM `import` is not natively supported without a transpilation step or a wrapper.","wrong":"import { WasmBuilder } from 'wasmbuilder';","symbol":"WasmBuilder","correct":"const WasmBuilder = require('wasmbuilder');"},{"note":"The main functionality is exposed through instantiating the WasmBuilder class.","symbol":"WasmBuilder instance","correct":"const builder = new WasmBuilder();"}],"quickstart":{"code":"const WasmBuilder = require('wasmbuilder');\nconst fs = require('fs');\n\n// Initialize the builder\nconst builder = new WasmBuilder();\n\n// Define an 'add' function that takes two i32 and returns one i32.\n// Its body in WASM bytecode (hex): (local.get 0) (local.get 1) (i32.add) (end)\n// This translates to the hex string: \"200020016a0b\"\nbuilder.addFunction(\n  \"add\",                  // function name for internal use\n  [\"i32\", \"i32\"],         // parameter types (two 32-bit integers)\n  [\"i32\"],                // return type (one 32-bit integer)\n  \"200020016a0b\"          // WASM bytecode as hex string\n);\n\n// Export the 'add' function so it can be called from JavaScript\nbuilder.exportFunction(\"add\", \"add\");\n\n// Build the WASM module to get its binary representation\nconst wasmBinary = builder.build();\n\n// Optionally, write the WASM binary to a file\nfs.writeFileSync('add.wasm', wasmBinary);\nconsole.log('add.wasm created successfully.');\n\n// Instantiate and use the generated WASM module\n(async () => {\n  try {\n    const { instance } = await WebAssembly.instantiate(wasmBinary, {});\n    const addResult = instance.exports.add(5, 7);\n    console.log(`Result of add(5, 7): ${addResult}`); // Expected output: 12\n  } catch (e) {\n    console.error(\"Error instantiating or running WASM module:\", e);\n  }\n})();","lang":"javascript","description":"This quickstart demonstrates how to create a simple WASM module containing an 'add' function, export it, build the binary, and then instantiate and execute it from JavaScript using direct WASM bytecode."},"warnings":[{"fix":"Consider using actively maintained WASM compilation tools (e.g., Emscripten, Rust/Wasm-bindgen, AssemblyScript) or more recent low-level WASM libraries for production use cases. For learning purposes, be aware of its outdated nature.","message":"The `wasmbuilder` package has been abandoned since its last update in October 2019 (version 0.0.16). It is not maintained, may contain unpatched security vulnerabilities, and is unlikely to be compatible with newer JavaScript/Node.js features or WASM specifications without significant manual intervention.","severity":"breaking","affected_versions":">=0.0.16"},{"fix":"Thoroughly consult the WebAssembly specification for instruction opcodes and module structure. Utilize WASM disassemblers and validators for debugging custom bytecode. Be prepared for extensive manual debugging.","message":"This library requires deep knowledge of WebAssembly bytecode and its hexadecimal representation. Constructing WASM modules manually via hex strings is error-prone and complex, even for simple operations.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure your project is configured for CommonJS, or use a build tool like Webpack/Rollup that can handle CJS modules in an ESM context. Alternatively, create a CJS wrapper file that exports the `WasmBuilder` class for ESM consumption.","message":"The library primarily uses CommonJS (`require`) syntax. Attempting to use it directly in a modern ESM (`import`) environment will result in errors.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Change your file to a CommonJS context (e.g., remove `\"type\": \"module\"` from `package.json`, use a `.cjs` file extension, or run with older Node.js versions). If forced to use ESM, consider dynamic `import('wasmbuilder')` or a build process to convert CJS to ESM.","cause":"Attempting to use `require('wasmbuilder')` in an ECMAScript Module (ESM) context (e.g., in a file with `\"type\": \"module\"` in `package.json` or a `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Double-check the WASM specification for correct opcodes and their arguments. Use a WASM disassembler on known-good WASM binaries to understand correct structure and hex representations for your desired logic. Ensure function parameters, return types, and local variables are correctly declared and used in the bytecode.","cause":"The hexadecimal bytecode provided to `addFunction` or other builder methods contains invalid WASM opcodes, incorrect operand types, or an improperly structured function body, leading to an invalid WASM module.","error":"TypeError: WebAssembly.instantiate(): Wasm code is not valid: unknown opcode"},{"fix":"Verify that `builder.exportFunction('internalName', 'externalName')` is called for every function you wish to expose, and that 'internalName' exactly matches the first argument given to `builder.addFunction`.","cause":"The `exportFunction` method was not called for the desired function, or the function name provided to `exportFunction` does not match the name used in `addFunction`, preventing it from being callable from JavaScript.","error":"TypeError: instance.exports.yourFunctionName is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}