Registry / communication / nice-grpc-web

nice-grpc-web

JSON →
library3.3.10jsnpmunverified

A TypeScript-first gRPC-Web client library for browsers. Current stable version is 3.3.10 with monthly releases. Key differentiators: full TypeScript support, async iterable for server-streaming, AbortController for cancellation, and client middleware for interceptors. Compliant with the official gRPC-Web specification, works with protobuf-es or protobufjs. Unlike grpc-web, it provides a Promise-based API with proper TypeScript types and supports cancelation.

npm install nice-grpc-web
INSTALL
IMPORT
SIG · NICE-GRPC-WEB
N
nice-grpc-web
communicationjavascriptv3.3.10
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.

createClient
import { createClient } from 'nice-grpc-web'
const { createClient } = require('nice-grpc-web')
ESM-only since v3; CommonJS require will fail.
GrpcWebClient
import { GrpcWebClient } from 'nice-grpc-web/client'
import { GrpcWebClient } from 'nice-grpc-web'
The client class is not exported from the main barrel; import from the specific module.
Client
import type { Client } from 'nice-grpc-web'
import { Client } from 'nice-grpc-web'
Client is a type; use import type to avoid runtime errors.

Shows how to create a gRPC-Web client from a service definition and client class generated by protobuf-es.

import { createClient } from 'nice-grpc-web'; import { GreeterClient } from './example/proto/example.client'; import { GreeterServiceDefinition } from './example/proto/example'; const client = createClient( GreeterServiceDefinition, GreeterClient, 'http://localhost:8080' ); const response = await client.sayHello({ name: 'Alice' }); console.log(response.message);
Debug
Known issues
breakingIn v3, the package became ESM-only. CommonJS require() will not work.
fix
Use ESM imports or switch to dynamic import() in CJS projects.
affects: >=3.0.0
deprecatedThe createClient function no longer accepts a constructor function for the client; it requires a generated client class.
fix
Pass the generated client class (e.g., GreeterClient) as the second argument.
affects: >=3.0.0
gotchaWhen using protobufjs, the generated client types may not match the expected interface; prefer protobuf-es for better TypeScript support.
fix
Use protobuf-es as the protobuf runtime for full type safety.
affects: >=1.0.0
breakingThe abortController option is replaced by AbortSignal in v3. Using abortController will throw an error.
fix
Pass signal from an AbortController instead of the controller itself.
affects: >=3.0.0
deprecatedServer-streaming responses are now async iterables instead of EventEmitters.
fix
Use for await...of instead of listening to events.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: Cannot use import statement outside a module
Trying to use ESM imports in a CommonJS project (v3 is ESM-only).
fix
Add "type": "module" to package.json or rename file to .mjs.
Uncaught (in promise) TypeError: client.sayHello is not a function
Generated client class missing from second argument of createClient.
fix
Pass the generated client class (e.g., GreeterClient) as the second argument.
Uncaught (in promise) Error: No transport configured
Missing transport import; required for gRPC-Web communication.
fix
Import and configure a transport like @nice-grpc/grpc-web-transport.
Upgrade
Version history
3.3.10latest on npm
Audit
Dependencies
protobuf-esoptionalRequired for generating TypeScript types from protobuf definitions when using protobuf-es runtime.
protobufjsoptionalAlternative runtime for protobuf message serialization, required if not using protobuf-es.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
nice-grpc-web — npm install nice-grpc-web · libregistry