Registry / serialization / flatc-wasm

flatc-wasm

JSON →
library26.1.32jsnpmunverified

FlatBuffers compiler (flatc) compiled to WebAssembly, enabling schema management, JSON/binary conversion, and code generation in Node.js (18+) and modern browsers without native dependencies. Current stable version 26.1.32, released February 2025. Key differentiators: self-contained with inlined WASM binaries, zero native deps, supports 13 code generation languages (C++, TypeScript, Go, Rust, Python, Java, etc.), per-field AES-256-CTR encryption, streaming APIs for large data, JSON Schema import/export, and embedded language runtimes. Licensed under Apache 2.0. Maintained by DigitalArsenal on GitHub.

npm install flatc-wasm
INSTALL
IMPORT
SIG · FLATC-WASM
F
flatc-wasm
serializationjavascriptv26.1.32
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.

FlatcRunner
✓ import { FlatcRunner } from 'flatc-wasm'
✗ const FlatcRunner = require('flatc-wasm').FlatcRunner
ES module import; also works with dynamic import()
createFlatcModule
✓ import { createFlatcModule } from 'flatc-wasm'
✗ const createFlatcModule = require('flatc-wasm')
Low-level module factory for manual WASM initialization
AlignedType
✓ import { AlignedType } from 'flatc-wasm'
✗ import { AlignedTypes } from 'flatc-wasm'
Enum used for aligned binary format; type import also available: import type { AlignedType }

Demonstrates loading a FlatBuffers schema, converting between JSON and binary, and generating TypeScript code using FlatcRunner.

import { FlatcRunner } from 'flatc-wasm'; import { readFileSync, writeFileSync } from 'fs'; async function main() { // Create runner instance const runner = await FlatcRunner.create(); // Load a FlatBuffers schema const schema = readFileSync('monster.fbs', 'utf8'); await runner.addSchema('monster', schema); // Convert JSON to FlatBuffer binary const jsonData = JSON.stringify({ name: 'Orc', hp: 300 }); const binary = await runner.jsonToBinary('monster', jsonData, 'MyGame.Sample.Monster'); writeFileSync('monster.bin', Buffer.from(binary)); // Convert binary back to JSON (auto-detects schema) const binaryBuf = readFileSync('monster.bin'); const jsonOut = await runner.binaryToJson('monster', new Uint8Array(binaryBuf)); console.log(jsonOut); // Generate TypeScript code const tsCode = await runner.generateCode('monster', 'typescript'); writeFileSync('monster_generated.ts', tsCode); } main().catch(console.error);
Debug
Known issues
breakingWASM module initialization changed from synchronous to async in v26.0.0. FlatcRunner.create() must be awaited.
fix
Use await FlatcRunner.create() instead of new FlatcRunner().
affects: >=26.0.0
deprecatedThe low-level API 'createFlatcModule' is deprecated in favor of 'FlatcRunner' since v25.12.0.
fix
Migrate to FlatcRunner API for easier usage and better error handling.
affects: >=25.12.0
gotchaBinary output from jsonToBinary is an ArrayBuffer, not a Buffer. Use Buffer.from() before writing to file.
fix
const buffer = Buffer.from(await runner.jsonToBinary(...));
affects: >=0.0.0
breakingNode.js minimum version raised to 18.0.0 in v25.0.0. Older versions are not supported.
fix
Upgrade Node.js to 18.0.0 or later.
affects: >=25.0.0
gotchaSchema names are case-sensitive and must match the schema file name (without .fbs). Adding a schema with the wrong name will fail silently.
fix
Ensure schema name matches the file stem, e.g., 'monster' for 'monster.fbs'.
affects: >=0.0.0
Errors
Common errors & fixes
Error: WebAssembly.instantiate(): expected magic word 00 61 73 6d
The WASM binary is corrupted or not fully loaded due to network issues in browser or incorrect bundler configuration.
fix
Ensure the WASM binary is served with the correct MIME type 'application/wasm' and loaded via fetch or import. In webpack, add a rule to load .wasm files as WebAssemblyModule.
TypeError: Cannot read properties of undefined (reading 'addSchema')
FlatcRunner.create() not awaited; runner object is undefined.
fix
Use const runner = await FlatcRunner.create();
Error: Schema 'monster' not found
Schema was not added before calling conversion or code generation functions.
fix
Call await runner.addSchema('monster', schemaContent) first.
RangeError: offset is out of bounds
ArrayBuffer passed to binaryToJson is too small or the binary format is malformed.
fix
Verify that the binary was generated by flatc or by jsonToBinary with the correct schema and root type.
Upgrade
Version history
26.1.32latest on npm
Audit
Dependencies
hd-wallet-wasmoptionalOptional dependency for HD key derivation used in encryption features
Agent activity
4 hits · last 30 days
node
4
Resources
flatc-wasm — npm install flatc-wasm · libregistry