Registry / devops / grpc-code-gen

grpc-code-gen

JSON →
library6.1.22jsnpmunverified

Code generator for gRPC services targeting TypeScript and JavaScript. Version 6.1.22 is current stable. Generates client/server code from proto files fetched via git URLs. Supports custom resolve paths, multiple git branches, and configuration file. Key differentiator: integrates proto fetching, code generation, and path resolution in one CLI tool, reducing boilerplate. Not widely adopted; primarily used in private Chinese ecosystems.

npm install grpc-code-gen
INSTALL
IMPORT
SIG · GRPC-CODE-GEN
G
grpc-code-gen
devopsjavascriptv6.1.22
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.

gen
import { gen } from 'grpc-code-gen'
import gen from 'grpc-code-gen'
gen is a named export, not default. Use destructured import.
base
const base = require('grpc-code-gen/build/base')
import base from 'grpc-code-gen/build/base'
Programmatic API exposed via require() to build/base. ESM import may fail due to CJS export.
cli
npx grpc-code-gen gen --help
npm grpc-code-gen gen
CLI is invoked via npx, not npm. Use npx or global install.

Creates a config file and runs code generation from a git proto repository with token authentication.

// grpc-code-gen.config.js module.exports = { gitUrls: [ { url: 'git@github.com:example/proto.git', branch: 'main' } ], accessToken: process.env.GIT_TOKEN || '', baseDir: __dirname + '/generated', target: 'typescript', grpcNpmName: '@grpc/grpc-js' }; // Run: npx grpc-code-gen gen
Debug
Known issues
breakingCJS require('grpc-code-gen') does not work; use require('grpc-code-gen/build/base')
fix
Change import to 'grpc-code-gen/build/base'
affects: >=6.0.0
gotchaGit URLs must be SSH format (git@...) or HTTPS with token. Non-standard formats may fail.
fix
Use git@ or https:// with accessToken
affects: >=1.0.0
gotchaConfig file must be CommonJS (module.exports). ES module .mjs config not supported.
fix
Use module.exports in .js file, not export default
affects: >=4.0.0
deprecatedOption 'grpcNpmName' default is 'grpc', but '@grpc/grpc-js' is recommended for modern Node.
fix
Set grpcNpmName: '@grpc/grpc-js' in config
affects: >=5.0.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc-code-gen/build/base'
Incorrect package path when using programmatic API
fix
Use require('grpc-code-gen/build/base')
TypeError: gen is not a function
Default import used instead of named import
fix
Use import { gen } from 'grpc-code-gen'
fatal: could not read Username for 'https://git.myscrm.cn': terminal prompts disabled
Missing accessToken or incorrect URL format
fix
Provide accessToken in config or use SSH URL
Upgrade
Version history
6.1.22latest on npm
Audit
Dependencies
grpcoptionalRequired for gRPC runtime (can be replaced by @grpc/grpc-js)
@grpc/grpc-jsoptionalAlternative gRPC runtime (specified via grpcNpmName option)
Agent activity
6 hits · last 30 days
node
6
Resources
grpc-code-gen — npm install grpc-code-gen · libregistry