Registry / devops / grpc-pbf-loader

grpc-pbf-loader

JSON →
library1.1.6jsnpmunverified

A utility for loading .proto files for gRPC using pbf as a serializer. Version 1.1.6 (latest) supports both synchronous and asynchronous loading of package definitions. Differentiates from @grpc/proto-loader by leveraging pbf for potentially faster serialization. Works with grpc or @grpc/grpc-js. Ships TypeScript types and has minimal dependencies. Stable, with low release cadence (last update over a year ago).

npm install grpc-pbf-loader
INSTALL
IMPORT
SIG · GRPC-PBF-LOADER
G
grpc-pbf-loader
devopsjavascriptv1.1.6
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.

packageDefinition
import { packageDefinition } from 'grpc-pbf-loader'
const { packageDefinition } = require('grpc-pbf-loader')
Module is ESM-only. Named export, not default. Use dynamic import or top-level await.
default
import grpcPbfLoader from 'grpc-pbf-loader'
const grpcPbfLoader = require('grpc-pbf-loader')
Default export exists and is the packageDefinition object. Requires ESM.
packageDefinitionLoader
const loader = require('grpc-pbf-loader').packageDefinition
CommonJS require pattern with named property. Works in Node >=8.
packageDefinition.load
const result = await packageDefinition.load('file.proto', options)
packageDefinition.loadSync('file.proto', options) // wrong for async
load is async, loadSync is synchronous. Both return package definition objects.

Shows ESM import, async loading of a .proto file, and creating a gRPC client.

import { packageDefinition } from 'grpc-pbf-loader'; import * as grpc from '@grpc/grpc-js'; async function main() { const protoPath = 'path/to/service.proto'; const options = { keepCase: true, includeDirs: ['./proto'] }; const definition = await packageDefinition.load(protoPath, options); const proto = grpc.loadPackageDefinition(definition); const client = new proto.mypackage.MyService('localhost:50051', grpc.credentials.createInsecure()); console.log('Client created'); } main().catch(console.error);
Debug
Known issues
gotchaModule is ESM-only; CommonJS require() may not work in Node <12 or without --experimental-modules flag.
fix
Use dynamic import() or upgrade Node to >=14 with ESM support.
affects: <1.0
breakingThe default export changed from a function to an object with packageDefinition property in v1.0.0.
fix
Use packageDefinition property explicitly: import { packageDefinition } from 'grpc-pbf-loader'.
affects: >=1.0.0
gotchaSynchronous loadSync may fail with large .proto files due to pbf serialization limits.
fix
Use async load() for larger schemas to avoid blocking the event loop.
affects: <=1.1.6
deprecatedThe 'grpc' package (not @grpc/grpc-js) is deprecated. Use @grpc/grpc-js instead.
fix
Replace require('grpc') with require('@grpc/grpc-js').
affects: >=0.15.0
Errors
Common errors & fixes
Error: Cannot find module 'protocol-buffers-schema'
Missing peer dependency protocol-buffers-schema.
fix
Install the dependency: npm install protocol-buffers-schema
TypeError: packageDefinition.load is not a function
Using default import incorrectly; load method exists on packageDefinition object.
fix
Use import { packageDefinition } from 'grpc-pbf-loader' instead of import grpcPbfLoader from 'grpc-pbf-loader'.
SyntaxError: Cannot use import statement outside a module
Trying to use ESM syntax without setting 'type': 'module' in package.json.
fix
Add "type": "module" to your package.json or use .mjs file extension.
Error: ENOENT: no such file or directory, open '...'
Proto file path not found or missing includeDirs.
fix
Ensure proto file exists and provide includeDirs option with correct search paths.
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies
pbfrequiredCore serializer for protocol buffers
protocol-buffers-schemarequiredParses .proto schema files
resolve-protobuf-schemarequiredResolves imported .proto file paths
Agent activity
6 hits · last 30 days
node
6
Resources
grpc-pbf-loader — npm install grpc-pbf-loader · libregistry