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.
ProductServiceService
✓ import { ProductServiceService } from './path/to/generated/product_grpc_pb';
✗ const ProductServiceService = require('./path/to/generated/product_grpc_pb').ProductServiceService;
Generated TypeScript files export named constants (e.g., ProductServiceService) which are gRPC service definitions. Use ES module import for consistency. CommonJS require works but TypeScript may complain without esModuleInterop.
product_pb
✓ import * as product_pb from './path/to/generated/product_pb';
✗ import product_pb from './path/to/generated/product_pb';
Generated protobuf message types are exported as a namespace; use 'import * as' to import all types. Default import will not work because there is no default export.
grpc
✓ import * as grpc from '@grpc/grpc-js';
✗ import grpc from '@grpc/grpc-js';
The @grpc/grpc-js package uses a namespace export; you must use 'import * as' to get the grpc object. Without this, TypeScript will throw 'Module has no default export'.
Shows global installation, protoc invocation (with three output plugins), and then TypeScript server snippet using the generated service definition.
// Install protoc-gen-grpc globally
npm install -g protoc-gen-grpc
# Generate JavaScript and TypeScript definitions for a .proto file
# Make sure protoc is installed (https://github.com/protocolbuffers/protobuf/releases)
protoc \
--js_out=import_style=commonjs,binary:./generated \
--grpc_out=grpc_js:./generated \
--ts_out=grpc_js:./generated \
--proto_path=./protos \
./protos/example.proto
# Now you can use the generated types in your TypeScript server
import * as grpc from '@grpc/grpc-js';
import { ExampleServiceService } from './generated/example_grpc_pb';
const server = new grpc.Server();
server.addService(ExampleServiceService, { /* your implementation */ });
Errors
Common errors & fixes
Error: Plugin "protoc-gen-ts" not found or is not executable.
protoc cannot find the protoc-gen-ts plugin; not installed or not in PATH.
fixEnsure protoc-gen-grpc-ts is installed globally (npm install -g protoc-gen-grpc-ts) and that protoc can find it. Alternatively, specify full path: --plugin=protoc-gen-ts=/path/to/protoc-gen-ts
error: unknown flag: --ts_out
The plugin is not properly registered; protoc does not recognize --ts_out.
fixMake sure the plugin executable is named exactly 'protoc-gen-ts' and is in PATH. Set unsafe-perm if needed. Verify with 'which protoc-gen-ts'.
Module not found: Can't resolve './path/to/generated/product_pb'
Generated JavaScript/TypeScript files are not in the expected location or import path is wrong.
fixCheck the output directory and adjust the import path in your TypeScript files. Use relative or absolute path as needed.
TypeError: Cannot read properties of undefined (reading 'ProductServiceService')
Attempting to import a service that does not exist; possibly wrong generated file or misnamed service.
fixVerify the .proto file defines the service correctly and that the generated file exports it with the exact name (e.g., ProductServiceService).
npm ERR! code EACCES npm ERR! syscall mkdir ...
Permission denied when trying to install globally without appropriate permissions.
fixUse npm config set prefix to a directory you own, or use sudo (not recommended), or install locally with npx.
Audit
Dependencies
protocoptionalprotoc (Protocol Buffers compiler) must be installed separately to run the protoc command with this plugin.
google-protobufrequiredRequired at runtime for the generated JavaScript protobuf messages; this plugin generates types that depend on the google-protobuf types.
grpcoptionalOne of the supported gRPC runtimes; if using @grpc/grpc-js, then grpc is optional.
@grpc/grpc-jsoptionalOne of the supported gRPC runtimes; if using grpc, then @grpc/grpc-js is optional.