Registry / devops / protoc-gen-grpc-js

protoc-gen-grpc-js

JSON →
library0.4.0jsnpmunverified

A protoc plugin that generates gRPC client and server service definitions for Node.js from Protocol Buffers. Version 0.4.0 targets gRPC-js (not grpc) and requires google-protobuf ^3.14.0. Outputs TypeScript-compatible JavaScript modules (ESM/CJS). Different from grpc-tools in that it generates idiomatic JS/TS service objects compatible with the @grpc/grpc-js library. Release cadence is irregular, currently stable but may have breaking changes before 1.0.

npm install protoc-gen-grpc-js
INSTALL
IMPORT
SIG · PROTOC-GEN-GRPC-JS
P
protoc-gen-grpc-js
devopsjavascriptv0.4.0
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.

generatePackageDefinition
import { generatePackageDefinition } from '@grpc/grpc-js'
const generatePackageDefinition = require('grpc').loadPackageDefinition
Generated files use @grpc/grpc-js, not the deprecated grpc package. The generation function is not directly exposed by this package; it's the output.
Generated service definition
import { MyServiceService } from './generated/myproto_grpc_pb'
Imports are relative to the output directory specified in protoc. File names are based on proto file names with _grpc_pb suffix.
Generated message classes
import { MyRequest, MyResponse } from './generated/myproto_pb'
import { MyRequest } from '@grpc/grpc-js'
Message classes are generated by the companion protoc-gen-js plugin and placed in separate _pb files, not in this package.

Installs the plugin, generates gRPC service stubs from a proto file, and creates a simple gRPC server using the generated code.

// 1. Install dependencies // npm install --save-dev protoc-gen-grpc-js google-protobuf @grpc/grpc-js // 2. Generate code from a .proto file // protoc --plugin=protoc-gen-grpc-js=./node_modules/.bin/protoc-gen-grpc-js \ // --js_out=import_style=commonjs,binary:./generated \ // --grpc-js_out=import_style=commonjs,binary:./generated \ // -I . myproto.proto // 3. Use the generated code // server.js const grpc = require('@grpc/grpc-js'); const { GreeterService } = require('./generated/helloworld_grpc_pb'); const { HelloRequest, HelloReply } = require('./generated/helloworld_pb'); const sayHello = (call, callback) => { const reply = new HelloReply(); reply.setMessage('Hello ' + call.request.getName()); callback(null, reply); }; const server = new grpc.Server(); server.addService(GreeterService, { sayHello }); server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { server.start(); console.log('Server running on port 50051'); });
Debug
Known issues
gotchaThis plugin generates code for @grpc/grpc-js, not the deprecated grpc package. Do not mix them.
fix
Use @grpc/grpc-js as runtime dependency and ensure imports reference it.
affects: >=0.0.0
breakingGenerated code uses ES modules by default; CommonJS output requires explicit import_style option.
fix
Add --grpc-js_out=import_style=commonjs,binary:./generated to your protoc command.
affects: >=0.3.0
deprecatedThe peer dependency google-protobuf is at version 3.x; google-protobuf 4.x is in alpha and unsupported.
fix
Stay on google-protobuf ^3.14.0 until this plugin is updated for v4.
affects: >=0.4.0
Errors
Common errors & fixes
Error: Cannot find module 'google-protobuf'
Missing peer dependency google-protobuf at runtime.
fix
Run npm install google-protobuf
Error: Invalid grpc message: Cannot read properties of undefined (reading 'serializeBinary')
Generated files are from the deprecated grpc package instead of @grpc/grpc-js.
fix
Ensure protoc-gen-grpc-js (not grpc-tools) is used and the --grpc-js_out plugin is correctly specified.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
google-protobufoptionalRequired peer dependency for generated code to work at runtime.
Agent activity
6 hits · last 30 days
node
6
Resources
protoc-gen-grpc-js — npm install protoc-gen-grpc-js · libregistry