Registry / devops / egg-grpc-client-ts

egg-grpc-client-ts

JSON →
library3.0.2jsnpmunverified

TypeScript gRPC client plugin for Egg.js framework, wrapping @grpc/grpc-js. Version 3.0.2 is the latest stable release with maintenance updates. Provides Egg-style declarative configuration for multiple gRPC clients, health checks, and distributed tracing via grpcMeta. Compared to egg-grpc-client, this plugin has TypeScript definitions and improved error metadata.

npm install egg-grpc-client-ts
INSTALL
IMPORT
SIG · EGG-GRPC-CLIENT-TS
E
egg-grpc-client-ts
devopsjavascriptv3.0.2
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.

grpcClient plugin config
exports.grpcClient = { enable: true, package: 'egg-grpc-client-ts' };
exports.grpcClient = { enable: true, package: 'egg-grpc-client' };
Plugin name in config must match the package name exactly.
gRPC client usage
const client = app.grpcClient.getClient('main'); const result = await client.sayHello({ name: 'world' });
const client = new GrpcClient();
Clients are obtained via app.grpcClient.getClient(name), not instantiated directly.
TypeScript type imports
import type { GrpcClient } from 'egg-grpc-client-ts';
import { GrpcClient } from 'egg-grpc-client-ts';
Use `import type` for type-only imports to avoid runtime errors.

Configures the egg-grpc-client-ts plugin and uses it in an Egg.js service to call a gRPC service.

// config/plugin.ts exports.grpcClient = { enable: true, package: 'egg-grpc-client-ts', }; // config/config.default.ts exports.grpcClient = { clients: [ { name: 'main', protoPath: 'app/proto/helloworld.proto', host: process.env.GRPC_HOST ?? 'localhost', port: Number(process.env.GRPC_PORT ?? '50051'), }, ], }; // app/service/Greeter.ts import { Application } from 'egg'; export default class GreeterService extends app.Service { async sayHello(name: string) { const client = this.app.grpcClient.getClient('main'); return client.sayHello({ name }); } }
Debug
Known issues
breakingVersion 2.x drops Node.js 8 support; minimum Node is 10.
fix
Upgrade to Node.js 10+ or stay on v1.x.
affects: >=2.0.0 <3.0.0
breakingVersion 3.0.0 changes gRPC library from grpc to @grpc/grpc-js.
fix
Ensure @grpc/grpc-js is installed (it's a dependency). Update any direct requires of 'grpc' to '@grpc/grpc-js'.
affects: >=3.0.0
deprecatedUsing CommonJS require() for plugin config is deprecated as of Egg 3.
fix
Use ES module syntax: `export default { grpcClient: { enable: true, package: 'egg-grpc-client-ts' } };`
affects: >=3.0.0
gotchaThe plugin does not automatically reconnect on connection loss. You must implement reconnection logic or use a connection pool.
fix
Wrap client calls with retry logic or use a higher-level library that supports reconnection.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
Version 3.x uses @grpc/grpc-js instead of grpc.
fix
Run `npm install @grpc/grpc-js` and update imports to use '@grpc/grpc-js'.
TypeError: app.grpcClient.getClient is not a function
Plugin not enabled or not loaded correctly.
fix
Check plugin.ts: exports.grpcClient = { enable: true, package: 'egg-grpc-client-ts' }; Also ensure plugin directory is in egg's plugin path.
Error: grpcClient config missing clients array
Missing or malformed config.default.js exports.grpcClient.clients.
fix
Set exports.grpcClient = { clients: [{ name, protoPath, host, port }] };
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredgRPC client implementation
eggrequiredEgg.js framework dependency for plugin loading and configuration
Agent activity
6 hits · last 30 days
node
6
Resources
egg-grpc-client-ts — npm install egg-grpc-client-ts · libregistry