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)
✓ import { EggPlugin } from 'egg'; const plugin: EggPlugin = { grpcClient: { enable: true, package: 'grpc-client-egg' } }; export default plugin
✗ const plugin = { grpcClient: { enable: true, package: 'grpc-client-egg' } }; module.exports = plugin
Must use EggPlugin type and ESM export for Egg.js 3+
this.app.grpcClient
✓ const client = this.app.grpcClient[name].service[package][service]
✗ const client = this.app.grpcClient['main'].greeter.Greeter
Access via app.grpcClient – correctly uses bracket notation for dynamic names
grpc client configuration
✓ import { EggAppConfig, PowerPartial } from 'egg'; const config: PowerPartial<EggAppConfig> = { grpcClient: { clients: [{ name: 'main', protoPath: 'app/proto/main', host: '0.0.0.0', port: 50051 }] } }; export default config
✗ module.exports = { grpcClient: { clients: [{ name: 'main', protoPath: 'app/proto/main', host: '0.0.0.0', port: 50051 }] } }
Must use PowerPartial and ESM export for type safety in Egg.js 3+
Shows complete setup: install, plugin enable, config with proto path, and using promisified client in a service.
// 1. Install
// npm i -S grpc-client-egg
// 2. Plugin config (plugin.ts)
import { EggPlugin } from 'egg'
const plugin: EggPlugin = {
grpcClient: {
enable: true,
package: 'grpc-client-egg',
},
}
export default plugin
// 3. Application config (config.default.ts)
import { EggAppConfig, PowerPartial } from 'egg'
export default () => {
const config: PowerPartial<EggAppConfig> = {
grpcClient: {
clients: [
{
name: 'main',
protoPath: 'app/proto/main',
host: process.env.GRPC_HOST ?? '0.0.0.0',
port: Number(process.env.GRPC_PORT ?? 50051),
},
],
},
}
return config
}
// 4. Service usage
import { Service } from 'egg'
interface GreeterService {
sayHello(params: { name: string }): Promise<{ message: string }>
}
export default class Greeter extends Service {
readonly service: GreeterService = this.app.grpcClient.main.greeter.Greeter
public async sayHello(name: string) {
return this.service.sayHello({ name })
}
}
Errors
Common errors & fixes
TypeError: Cannot read property 'Greeter' of undefined
grpcClient service not initialized or invalid client name/service path
fixVerify client name 'main' matches config, and that proto defines 'greeter.Greeter' service.
Error: Cannot find module 'grpc'
Peer dependency 'grpc' not installed
Error: ENOENT: no such file or directory, open '/path/to/app/proto/main.proto'
protoPath config is incorrect or file missing
fixEnsure protoPath is relative to app root or absolute, and the proto file exists.
Error: 14 UNAVAILABLE: failed to connect to all addresses
gRPC server host/port incorrect or server down
fixCheck host and port in config; ensure gRPC server is running and accessible.
TypeError: this.app.grpcClient is undefined
Plugin not enabled or package name wrong
fixConfirm plugin.ts has correct package name 'grpc-client-egg' and enable: true.
Audit
Dependencies
eggrequiredRequires Egg.js application framework to load as plugin
grpcrequiredCore gRPC library for JavaScript