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.
GRPCError
✓ const GRPCError = require('grpc-error')
✗ import GRPCError from 'grpc-error'
Package is CJS-only; does not support ESM imports directly.
GRPCError
✓ const { GRPCError } = require('grpc-error')
✗ const GRPCError = require('grpc-error').GRPCError
Default export is the class; named import does not exist.
GRPCError
✓ const GRPCError = require('grpc-error')
✗ const grpcError = require('grpc-error')
Common usage expects 'GRPCError' as the variable name.
Shows creating GRPCError with status code from @grpc/grpc-js and with custom code and metadata.
const GRPCError = require('grpc-error');
const grpc = require('@grpc/grpc-js');
// Create gRPC error with status code
const error = new GRPCError('Invalid argument', grpc.status.INVALID_ARGUMENT);
console.log(error.message); // 'Invalid argument'
console.log(error.code); // 3
// Create with custom code and metadata
const error2 = new GRPCError('Boom', 2000, { status_code: 'INVALID_TOKEN' });
console.log(error2.code); // 2000
console.log(error2.metadata.getMap()); // { status_code: 'INVALID_TOKEN' }
Errors
Common errors & fixes
TypeError: Class constructor GRPCError cannot be invoked without 'new'
Trying to call GRPCError as a function without 'new'.
fixInstantiate with 'new GRPCError(...)'
Module not found: Can't resolve 'grpc'
Missing peer dependency '@grpc/grpc-js' (or older 'grpc' package).
fixRun: npm install @grpc/grpc-js
Error: grpc.Metadata is not a constructor
Using @grpc/grpc-js version that changed the export path.
fixEnsure you require: const grpc = require('@grpc/grpc-js'); Audit
Dependencies
@grpc/grpc-jsoptionalPeer dependency for gRPC status codes and Metadata class