protoc (Protocol Buffers Compiler) - WebAssembly

raw JSON →
0.0.7 verified Fri May 01 auth: no javascript deprecated

An experimental WebAssembly port of Google's protoc compiler, compiled from C++ protobuf source. Version 0.0.7 provides protoc functionality for Node.js and browser environments without native binaries. Distributed as an npm package, it supports generating code from .proto files for all standard languages (e.g., JavaScript, Python, C++, Java). The package exposes a command-line tool (when installed globally) and a programmable module. Current release cadence is low (last release 6+ years ago); it is not maintained by Google directly but is a community build. Key differentiator: runs entirely in-process/browser, no native protoc binary required.

error Cannot find module 'google-protocol-compiler'
cause Package not installed or missing from node_modules.
fix
Run 'npm install google-protocol-compiler' or add to package.json.
error TypeError: generator.onReady is not a function
cause Module not loaded correctly (e.g., required before onReady is available or wrong import style).
fix
Ensure require('google-protocol-compiler') is used (not import) and that the variable is named 'generator'.
error Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'generateCode')
cause Trying to call generateCode before onReady has fired, or the module hasn't initialized.
fix
Always invoke generateCode inside the onReady callback or after a promise that waits for readiness.
deprecated This package is experimental and no longer maintained. Use the official native protoc binary or @bufbuild/protoc-gen-es for modern protobuf code generation.
fix Switch to native protoc (https://github.com/protocolbuffers/protobuf/releases) or protobuf-es (https://github.com/bufbuild/protobuf-es).
gotcha onReady callback may never fire if the WASM file fails to load (e.g., missing MIME type in browser).
fix Ensure WASM is served with application/wasm MIME type, or set a timeout to detect failures.
gotcha generateCode language parameter is case-sensitive. 'Javascript' works, 'javascript' does not.
fix Use 'Javascript' (capital J, rest lowercase) or refer to languageList.
gotcha The package bundles a large WASM binary (~5 MB). First use can be slow due to WASM compilation.
fix Warm up the module early with onReady, or consider streaming compilation in browsers.
npm install google-protocol-compiler
yarn add google-protocol-compiler
pnpm add google-protocol-compiler

Shows how to initialize the WASM compiler, generate JavaScript code from a .proto string, and log the output files.

const generator = require('google-protocol-compiler');
generator.onReady(() => {
  const name = 'test.proto';
  const content = 'syntax = "proto3";\npackage test;\nmessage TestMsg { string name = 1; }';
  const result = generator.generateCode(name, content, 'Javascript', 'import_style=commonjs');
  if (result.error) {
    console.error('Error:', result.error);
  } else {
    result.files.forEach(f => console.log(f.name, ':', f.content.substring(0, 50)));
  }
});