Generated proto types are not valid for ES modules
- Dominant language
- TypeScript
- Stars
- 4.8k
- Forks
- 716
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 10
Description
### Environment
- Mac m1 2020
- Node 18.14.2
- nvm
- @grpc/grpc-js: "^1.8.13",
- @grpc/proto-loader: "^0.7.6"
### Problem description
The generated file(s) are not compatible with ES modules.
### Reproduction steps
- Package.json with `"type": "module"`
- tsconfig with `"module": "node16", "moduleResolution": "node16"`
- generate types using command:
```
proto-loader-gen-types --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=src/generated src/.proto
```
### How to Fix
The generated import should end with "**.js**": (See image below)
```typescript
import type { BookItem as _bookStorePackage_BookItem, BookItem__Output as _bookStorePackage_BookItem__Output } from '../bookStorePackage/BookItem.js';
```
### Additional context
Current error:
```bash
error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './bookStorePackage/Book.js'?
```
Proto file:
```typescript
syntax = 'proto3';
package bookStorePackage;
service Book {
rpc createBook (BookItem) returns (BookItem);
}
message BookItem {
int32 id = 1;
string book = 2;
}
```
Image with error:

Contributor guide
Assessment
This issue has not been assessed yet.