tatethurston / TwirpScript

A protobuf RPC framework for JavaScript and TypeScript
MIT License
142 stars 13 forks source link

TypeScript imports broken since use of ProtoScript #202

Closed zolex closed 2 years ago

zolex commented 2 years ago

since version 0.0.61 when ProtoScript is used by twirpscript to generate typescript code, the imports of the messages from the services are broken:

it outputs .pb.ts files but the import statements are .pb.js

generated files:

image

import statements before 0.0.61

image

import statements since 0.0.61

image
tatethurston commented 2 years ago

@zolex Thanks for reporting this. This change is intentional, and was made specifically to support the TypeScript compiler. The full extension path is expected — it’s required for ES modules which don’t implicitly assume a js extension like commonjs does. The TypeScripts compiler expects js extensions and not ts extensions because the compiler does not manipulate import paths: https://www.typescriptlang.org/docs/handbook/esm-node.html. The TypeScript team may reevaluate this in 4.9.

I suspect you're using something other than the TypeScript compiler, such as webpack and ts-loader, to compile your TypeScript code? https://github.com/TypeStrong/ts-loader/issues/1383.

@andrewbeckman ran into this as well and reported it in https://github.com/tatethurston/TwirpScript/issues/192. Given this rough edge, I'm open to reevaluating this.

tatethurston commented 2 years ago

This could look like the following:

zolex commented 2 years ago

That's interesting, thanks for the detailed answer.

Our Frontend team is using gatsby, do you know how to address this issue here?

tatethurston commented 2 years ago

@zolex I've published https://github.com/tatethurston/TwirpScript/releases/tag/v0.0.64 with the changes I mentioned above. This should "just work" for you -- let me know if you encounter any issues.

zolex commented 2 years ago

Thanks man, I'll ask our responsible dev on monday to see if it solves the issues.