Registry / testing / grpc-ts-protoc-gen

grpc-ts-protoc-gen

JSON →
library0.1.1jsnpmunverified

Protoc plugin for generating TypeScript declarations (.d.ts) for gRPC service definitions. Version 0.1.1, no recent releases. It depends on ts-protoc-gen and generates CommonJS-compatible type definitions matching grpc-web or grpc JavaScript output. Differentiates from alternatives by focusing purely on type definitions for gRPC services, not message classes.

npm install grpc-ts-protoc-gen
INSTALL
IMPORT
SIG · GRPC-TS-PROTOC-GEN
G
grpc-ts-protoc-gen
testingjavascriptv0.1.1
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.

UserServiceClient
import { UserServiceClient } from './generated/users_grpc_pb'
import { UserServiceClient } from './generated/users_pb'
Service client classes are generated in separate *_grpc_pb files, not in message files
GetUserRequest
import { GetUserRequest } from './generated/users_pb'
import { GetUserRequest } from './generated/users_grpc_pb'
Message types are in *_pb files, service types in *_grpc_pb files
protoc-gen-grpc-ts
protoc --plugin=protoc-gen-grpc-ts=./node_modules/.bin/protoc-gen-grpc-ts
protoc --grpc-ts_out=. --plugin=protoc-gen-ts=./path
Must specify correct plugin name and path for grpc-ts; also requires ts-protoc-gen plugin for message types

Installs the plugin and protoc, generates gRPC TypeScript definitions, and demonstrates using a generated client.

npm install --save-dev grpc-ts-protoc-gen ts-protoc-gen google-protobuf grpc-web # Generate code protoc \ --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \ --plugin=protoc-gen-grpc-ts=./node_modules/.bin/protoc-gen-grpc-ts \ --js_out=import_style=commonjs,binary:./generated \ --ts_out=./generated \ --grpc-web_out=import_style=typescript,mode=grpcweb:./generated \ --grpc-ts_out=./generated \ path/to/service.proto // Use generated code: import { UserServiceClient } from './generated/users_grpc_pb'; import { GetUserRequest } from './generated/users_pb'; const client = new UserServiceClient('http://localhost:8080', null, null); const req = new GetUserRequest(); req.setUsername('johndoe'); client.getUser(req, {}, (err, user) => { console.log(user); });
Debug
Known issues
breakingRequires ts-protoc-gen to be run separately; missing it will cause missing type definitions for messages
fix
Install ts-protoc-gen and add --ts_out flag to protoc invocation
affects: >=0.0.0
deprecatedPackage uses deprecated grpc module; newer projects should use @grpc/grpc-js
fix
Switch to @grpc/grpc-js and use grpc-web mode if browser, or consider grpc-tools
affects: >=0.0.0
gotchaGenerated .d.ts files assume Node.js CommonJS; may require additional setup for bundlers
fix
Use webpack or rollup with appropriate plugins to handle protobuf runtime resolution
affects: >=0.0.0
breakingPlugin binary name is 'protoc-gen-grpc-ts', but some projects mistakenly use 'grpc-ts-protoc-gen'
fix
Set PROTOC_GEN_GRPC_TS_PATH=./node_modules/.bin/protoc-gen-grpc-ts
affects: >=0.0.0
Errors
Common errors & fixes
protoc-gen-grpc-ts: program not found or is not executable
The plugin path is incorrect or not executable; protoc cannot find the plugin binary
fix
Install the package and use the correct path: --plugin=protoc-gen-grpc-ts=./node_modules/.bin/protoc-gen-grpc-ts
Cannot find module './generated/users_grpc_pb'
The generated types are missing because the --grpc-ts_out flag was not used during protoc invocation
fix
Add --grpc-ts_out=<out_dir> to your protoc command
TypeError: users_pb is undefined
Protobuf JavaScript runtime not imported or generated .js files not included in bundle
fix
Ensure google-protobuf is installed and generated .js files are included in your build/load path
Property 'setUsername' does not exist on type 'GetUserRequest'
TypeScript definitions are missing setter methods if ts-protoc-gen has not been run
fix
Run protoc with --ts_out flag alongside --grpc-ts_out using ts-protoc-gen plugin
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
ts-protoc-genrequiredRequired for generating TypeScript definitions for protobuf messages; this plugin only handles gRPC service stubs
grpcoptionalRuntime dependency for gRPC client/server implementations used in generated code
Agent activity
11 hits · last 30 days
node
10
Resources
grpc-ts-protoc-gen — npm install grpc-ts-protoc-gen · libregistry