-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating TypeScript files from proto files that import other proto files is leading to js imports #192
Comments
Hey @andrewbeckman the full extension path is expected — it’s required for ES modules which don’t implicitly append 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 What is the error you’re encountering? And what version of TypeScript are you using? |
Here's my tsconfig in case it helps
|
Thanks @andrewbeckman, I'll look into this. There is likely a rough edge here, sorry about that. NextJS builds commonjs for the server build and esm for the client, so it sits right in the middle of a difficult transitional period for the JS ecosystem. In the meantime, you may be able to resolve this by updating your tsconfig |
Okay thanks @tatethurston. I had already tried updating the |
Cool, worth a try. Yeah, any project imports that aren't valid ESM would fail under the nodenext setting. |
@andrewbeckman Could you update to TS 4.7 (4.7.4 is the latest version) and let me know if that resolves the issue for you? |
I had already tried this as well. Unfortunately, same issue. |
Does
|
Yes! |
Awesome. I suspect this is an issue with next’s build process. In particular, I suspect they’re using a babel plugin for ts compilation and it doesn’t have the same behavior as the TS compiler. |
Alright I chased this down and the issue is a difference between the TypeScript compiler and webpack: TypeStrong/ts-loader#1383 Webpack introduced Here's an example of wiring this up: https://github.com/tatethurston/TwirpScript/pull/195/files#diff-02b18277d8fea71eaebddca674b4e25b357dcc8acb1feebfcc3573d015efb989 It looks like the TypeScript team may reevaluate this in 4.9 |
LMK if this doesn't resolve the issue for you @andrewbeckman, and 🤞 that this step can be eradicated once TS 4.9 lands. |
Thanks for hunting this down. I saw this and looked into modifying the webpack config and Next seems to allow it though it discourages it. |
Yep: https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config. I wouldn’t be concerned about risk here. The caution is intended for things that depend on or would interfere with Nextjs’ webpack configuration, which this does not.
|
@andrewbeckman I've released https://github.com/tatethurston/TwirpScript/releases/tag/v0.0.64 which removes the need for the |
@tatethurston Thanks for the heads up! We ended up making the switch to https://github.com/timostamm/protobuf-ts as we didn't want to go down the path of customizing our webpack config. Next time I have some time on my hands, will be sure to check out how things have progressed and decide if we should switch back! |
Related: TwirpScript now includes a NextJS example: https://github.com/tatethurston/twirpscript/tree/main/examples/nextjs |
I have a
proto
file with the following import line:And in the generated
.pb.ts
file, there's the following line:My twirp config is as follows:
Should the generated import statement be importing from
"../proto/uuid/models.pb.ts"
or even just"../proto/uuid/models.pb"
given that the generated file being imported is ats
file not ajs
file? I am currently running into blocking errors trying to build the generated code with Next.js because of this. I can try and work around those build issues, but it seems like this may genuinely be unintended.The text was updated successfully, but these errors were encountered: