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); });
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
fixInstall 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
fixAdd --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
fixEnsure 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
fixRun protoc with --ts_out flag alongside --grpc-ts_out using ts-protoc-gen plugin
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