{"id":25593,"library":"flatc-wasm","title":"flatc-wasm","description":"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.","status":"active","version":"26.1.32","language":"javascript","source_language":"en","source_url":"https://github.com/DigitalArsenal/flatbuffers","tags":["javascript","flatbuffers","flatc","wasm","webassembly","serialization","schema","compiler","codegen","typescript"],"install":[{"cmd":"npm install flatc-wasm","lang":"bash","label":"npm"},{"cmd":"yarn add flatc-wasm","lang":"bash","label":"yarn"},{"cmd":"pnpm add flatc-wasm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Optional dependency for HD key derivation used in encryption features","package":"hd-wallet-wasm","optional":true}],"imports":[{"note":"ES module import; also works with dynamic import()","wrong":"const FlatcRunner = require('flatc-wasm').FlatcRunner","symbol":"FlatcRunner","correct":"import { FlatcRunner } from 'flatc-wasm'"},{"note":"Low-level module factory for manual WASM initialization","wrong":"const createFlatcModule = require('flatc-wasm')","symbol":"createFlatcModule","correct":"import { createFlatcModule } from 'flatc-wasm'"},{"note":"Enum used for aligned binary format; type import also available: import type { AlignedType }","wrong":"import { AlignedTypes } from 'flatc-wasm'","symbol":"AlignedType","correct":"import { AlignedType } from 'flatc-wasm'"}],"quickstart":{"code":"import { FlatcRunner } from 'flatc-wasm';\nimport { readFileSync, writeFileSync } from 'fs';\n\nasync function main() {\n  // Create runner instance\n  const runner = await FlatcRunner.create();\n  \n  // Load a FlatBuffers schema\n  const schema = readFileSync('monster.fbs', 'utf8');\n  await runner.addSchema('monster', schema);\n  \n  // Convert JSON to FlatBuffer binary\n  const jsonData = JSON.stringify({ name: 'Orc', hp: 300 });\n  const binary = await runner.jsonToBinary('monster', jsonData, 'MyGame.Sample.Monster');\n  writeFileSync('monster.bin', Buffer.from(binary));\n  \n  // Convert binary back to JSON (auto-detects schema)\n  const binaryBuf = readFileSync('monster.bin');\n  const jsonOut = await runner.binaryToJson('monster', new Uint8Array(binaryBuf));\n  console.log(jsonOut);\n  \n  // Generate TypeScript code\n  const tsCode = await runner.generateCode('monster', 'typescript');\n  writeFileSync('monster_generated.ts', tsCode);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Demonstrates loading a FlatBuffers schema, converting between JSON and binary, and generating TypeScript code using FlatcRunner."},"warnings":[{"fix":"Use await FlatcRunner.create() instead of new FlatcRunner().","message":"WASM module initialization changed from synchronous to async in v26.0.0. FlatcRunner.create() must be awaited.","severity":"breaking","affected_versions":">=26.0.0"},{"fix":"Migrate to FlatcRunner API for easier usage and better error handling.","message":"The low-level API 'createFlatcModule' is deprecated in favor of 'FlatcRunner' since v25.12.0.","severity":"deprecated","affected_versions":">=25.12.0"},{"fix":"const buffer = Buffer.from(await runner.jsonToBinary(...));","message":"Binary output from jsonToBinary is an ArrayBuffer, not a Buffer. Use Buffer.from() before writing to file.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Node.js to 18.0.0 or later.","message":"Node.js minimum version raised to 18.0.0 in v25.0.0. Older versions are not supported.","severity":"breaking","affected_versions":">=25.0.0"},{"fix":"Ensure schema name matches the file stem, e.g., 'monster' for 'monster.fbs'.","message":"Schema names are case-sensitive and must match the schema file name (without .fbs). Adding a schema with the wrong name will fail silently.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'-256':62 '13':47 '18':20 '2.0':80 '2025':33 '26.1.32':30 'ae':61 'apach':79 'api':66 'binari':42 'browser':23 'c':51 'code':16,48 'codegen':94 'compil':5,7,93 'contain':38 'convers':14 'ctr':63 'current':27 'data':69 'dep':45 'depend':26 'differenti':35 'digitalarsen':83 'embed':74 'enabl':10 'encrypt':64 'etc':57 'februari':32 'field':60 'flatbuff':4,87 'flatc':2,6,88 'flatc-wasm':1 'generat':17,49 'github':85 'go':53 'import/export':72 'inlin':40 'java':56 'javascript':86 'json':70 'json/binary':13 'key':34 'languag':50,75 'larg':68 'licens':77 'maintain':81 'manag':12 'modern':22 'nativ':25,44 'node.js':19 'per':59 'per-field':58 'python':55 'releas':31 'runtim':76 'rust':54 'schema':11,71,92 'self':37 'self-contain':36 'serial':91 'stabl':28 'stream':65 'support':46 'typescript':52,95 'version':29 'wasm':3,41,89 'webassembl':9,90 'without':24 'zero':43","created_at":"2026-05-01T13:45:34.356715+00:00","updated_at":"2026-05-01T13:45:34.356715+00:00","problems":[{"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.","cause":"The WASM binary is corrupted or not fully loaded due to network issues in browser or incorrect bundler configuration.","error":"Error: WebAssembly.instantiate(): expected magic word 00 61 73 6d"},{"fix":"Use const runner = await FlatcRunner.create();","cause":"FlatcRunner.create() not awaited; runner object is undefined.","error":"TypeError: Cannot read properties of undefined (reading 'addSchema')"},{"fix":"Call await runner.addSchema('monster', schemaContent) first.","cause":"Schema was not added before calling conversion or code generation functions.","error":"Error: Schema 'monster' not found"},{"fix":"Verify that the binary was generated by flatc or by jsonToBinary with the correct schema and root type.","cause":"ArrayBuffer passed to binaryToJson is too small or the binary format is malformed.","error":"RangeError: offset is out of bounds"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://flatbuffers.dev/","github":"https://github.com/DigitalArsenal/flatbuffers","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/flatc-wasm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-01","next_check":"2026-07-30","install_tag":null}}