openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

Support `moduleResolution: nodenext`

Open ballcoach12 opened this issue 1 year ago • 4 comments

Description

I have a package.json file where moduleResolution is set to nodenext. Thus, import statements require the .js file extension, but the generated code does not include them. Is there a configuration setting that will force the code generator to insert the required .js extension on the imports?

ballcoach12 avatar Apr 23 '24 14:04 ballcoach12

Hey @ballcoach12, not at the moment, but my initial reaction is that this should be trivial to add

mrlubos avatar Apr 23 '24 14:04 mrlubos

@mrlubos, thanks for the quick reply, and I am quite impressed with how you guys are willing to make this package better and better!

ballcoach12 avatar Apr 23 '24 14:04 ballcoach12

@mrlubos I have a created a fix for this, but I wasn't able to get all the tests working, would it be possible for you to help with this? I will open a draft PR today. Thanks :D

omridevk avatar May 26 '24 10:05 omridevk

+1 to this issue. Would very much love to have the extensions in the imports.

BrandonArmand avatar Aug 30 '24 18:08 BrandonArmand

Any progress or updates? We're considering including @hey-api/openapi-ts in a new project, but this is blocking us.

alorle avatar Apr 30 '25 16:04 alorle

I am running into this issue also too now.

DanielRivers avatar May 01 '25 20:05 DanielRivers

@DanielRivers Did you change your project settings or it's a new project?

mrlubos avatar May 02 '25 06:05 mrlubos

Image

mrlubos avatar May 02 '25 20:05 mrlubos

This will be available in the next release and it should just work™. If you need to preserve the old behaviour, set output.tsConfigPath to off. If your tsconfig file is located in a nested folder, you can use output.tsConfigPath to point to that file as well. If none of this helps, it's likely because you're using an older configuration – comment here and I'll see what I can do.

mrlubos avatar May 04 '25 05:05 mrlubos

Hello, First, thank you for the work you did. hey-api is awesome, really !

In my workflow, I run the createClient function from a provider.generator.ts file with tsx. It seems that hey-api do not to take my tsconfig.json.

Here is a stackblitz to reproduce the issue: https://stackblitz.com/edit/stackblitz-starters-kf85xyx5?file=index.ts

If you check the generated files, imports are appended with .js.

Thank you very much :)

Wassim24 avatar May 05 '25 16:05 Wassim24

@Wassim24 omitting tsConfigPath in your example or setting it to path.join(__dirname, 'tsconfig.json') works, both will append .js. I might need to look at debugging this better, not sure which path it's resolving to in your example. Even when I changed it to a relative path ./tsconfig.json it didn't work, it might be related to running it through tsx or createClient(). Would need to debug more! Let me know if one of those 2 approaches I shared works for you

mrlubos avatar May 05 '25 16:05 mrlubos

Hello @mrlubos, Using the path.join works correctly, if i have a little time, i could investigate more about the issue. Thanks !

Wassim24 avatar May 06 '25 08:05 Wassim24

Don't worry about it, you'd need to run the source. I'll have a look at some point

mrlubos avatar May 06 '25 10:05 mrlubos