Webpack loader for translating .proto definitions into protobuf.js modules, equivalent to running the pbjs CLI at build time. Current stable version is 3.1.1, released January 2025 with async/await refactor and custom TypeScript output locations. Requires webpack ^5.0.0 (breaking change from v2 to v3 dropped webpack 4 support). Supports both static-module and json-module targets, and optional pbts TypeScript declaration generation. Alternatives: grpc-tools or manual pbjs invocation. Release cadence irregular, maintained by kmontag.
npm install protobufjs-loaderVerified import paths — ran on the pinned version, not inferred.
Configure webpack to load .proto files via protobufjs-loader, then import them as Root objects in your code.
Upgrade to webpack ^5.0.0, or stay on v2.x if you need webpack 4.
Upgrade Node to >=12.0.0 and ensure compatibility with protobufjs v7.
If using pbts output option, the function now receives (protobufFile) and returns a path or promise. See docs.
Ensure the loader is applied to .proto files, and that protobufjs is installed (as a direct dependency, not just dev).
Set target to 'static-module' or omit the option to use default.
Run: npm install protobufjs
Add protobufjs-loader rule to webpack.config.js: { test: /\.proto$/, use: 'protobufjs-loader' }Check valid pbjs CLI options. Common valid args: --target, --path, --no-create, --no-verify, --no-convert, --no-delimited, --no-beautify, --no-comments, --no-service, --no-typeurl, --no-stream
Ensure pbts.output is a function returning a string, e.g., (file) => `${file}.d.ts`