grpc / grpc/grpc-node

Re-exported types in grpc-js are not compatible with TypeScript's `--isolatedModules` flag

Open
#2,400 0 comments 0 reactions 0 assignees View on GitHub
package: @grpc/grpc-js
Dominant language
TypeScript
Stars
4.8k
Forks
716
Avg merge
2d 3h
Merged PRs (30d)
10

Description

### Problem description
We are investigating the use of gRPC-JS in a Dockerized NextJS (13) environment with TypeScript. It all works fine in development mode, but when we try to build the application we're hitting a wall where TypeScript complains about gRPC-JS not re-exporting types the way later versions of TypeScript expect it to. The error thrown by TS is the following (the actual file that errors out differs with each approach, either regular build or via Dockerfile)

```
./node_modules/@grpc/grpc-js/src/experimental.ts:3:3
Type error: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
```

### Reproduction steps
Bare example is to load a clean NextJS+TS app, which as of writing comes with Typescript 5.0.2 (but the issue exists at least as early as 4.9.5)
We'll have to edit `tsconfig.json` to enable esnext target and get past the first build errors, but after that it will halt on the bug I described. Workarounds involving weaking tsconfig to set `isolatedModules : false` or `js: react-jsx` do not work as they get overruled by the builder.

Repo to clone -> https://github.com/maxsteenbergen/grpcjs-ts-exported-types-bug

### Environment
- macOS 13.2, 2020 Intel iMac
- Node v18.12.1 via NVM
-"@grpc/grpc-js": "^1.8.13"

### Additional context
The build works fine if we set `ignoreBuildErrors: true` in next.config.js, so it's really just a matter of explicitly exporting types to appease TS.
Also, you don't have to actually the functions just yet: just importing them somewhere is enough for the error to pop up.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.