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.
ResilientGrpcClient
✓ import { ResilientGrpcClient } from 'grpc-resilient'
✗ const { ResilientGrpcClient } = require('grpc-resilient')
Package is ESM-only; CommonJS require will fail with ERR_REQUIRE_ESM.
GatewayGrpcClient
✓ import { GatewayGrpcClient } from 'grpc-resilient/gateway'
✗ import { GatewayGrpcClient } from 'grpc-resilient'
GatewayGrpcClient is exported from a subpath export 'grpc-resilient/gateway', not the main package.
type GrpcLogger
✓ import type { GrpcLogger } from 'grpc-resilient'
Use 'import type' for type-only imports to avoid runtime bundling issues.
Shows how to extend ResilientGrpcClient to create a typed microservice client with singleton pattern and generic call method.
import { ResilientGrpcClient, type GrpcLogger } from 'grpc-resilient';
import { fileURLToPath } from 'url';
const logger: GrpcLogger = console;
class UserServiceClient extends ResilientGrpcClient {
private static instance: UserServiceClient | null = null;
private constructor(grpcUrl: string, logger: GrpcLogger) {
super({
serviceName: 'UserService',
grpcUrl,
protoFile: 'user.proto',
packageName: 'myapp.user',
serviceClassName: 'UserService',
protosPath: fileURLToPath(new URL('./protos', import.meta.url)),
logger,
timeoutMs: 5000,
retryCount: 3,
enableFallbackCache: true,
});
}
static getInstance(grpcUrl: string, logger: GrpcLogger): UserServiceClient {
if (!UserServiceClient.instance) {
UserServiceClient.instance = new UserServiceClient(grpcUrl, logger);
}
return UserServiceClient.instance;
}
async getUser(userId: string) {
return this.call<{ userId: string }, { id: string; name: string }>('GetUser', { userId });
}
}
const client = UserServiceClient.getInstance(process.env.GRPC_URL ?? 'localhost:50051', logger);
const user = await client.getUser('123');
console.log(user);
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Using require() on an ESM-only package from CommonJS.
fixChange to import { ResilientGrpcClient } from 'grpc-resilient'; or use dynamic import(). Error: ENOENT: no such file or directory, open 'user.proto'
protosPath is relative or the proto file is missing at the specified path.
fixProvide an absolute path to the protos directory and ensure the proto file exists.
TypeError: (0 , grpc_resilient.GatewayGrpcClient) is not a constructor
Imported GatewayGrpcClient from wrong path; it's undefined.
fixImport GatewayGrpcClient from 'grpc-resilient/gateway'.
Audit
Dependencies
@grpc/grpc-jsrequiredRequired peer dependency for core gRPC functionality
@grpc/proto-loaderrequiredRequired peer dependency for loading .proto files