kiota-typescript icon indicating copy to clipboard operation
kiota-typescript copied to clipboard

Add .js Extensions to Imports statements

Open rkodev opened this issue 10 months ago • 2 comments

We need to evaluate whether to add .js extensions to import statements across all packages in this repository.

Verify the configuration of tsconfig. Depending on the options set, it can:

  • Automatically add the missing .js extension or not.
  • Automatically add index or not.

Additionally, define the hows and whys of this process.

rkodev avatar Mar 13 '25 13:03 rkodev

I noticed that the Kiota lib I generated (using V 1.27.0) there were quite a few imports statements pointing to .js files....that don't exist since the client generates .ts assets. I removed all then ".js" manually and the client built fine after that but it does seem like there's an issue here.

EricAtMSFT avatar Jun 19 '25 18:06 EricAtMSFT

@EricAtMSFT the reason why kiota generates typescript code with a .js extension for all relative imports is because it's required by the ESM specification and its implementation through node/TypeScript. Let us know if you have any additional comments or questions.

baywet avatar Jun 23 '25 16:06 baywet

@EricAtMSFT the reason why kiota generates typescript code with a .js extension for all relative imports is because it's required by the ESM specification and its implementation through node/TypeScript. Let us know if you have any additional comments or questions.

Hmm, this is the first I've learned of that. I haven't seen any library adhere to that standard. So in typescript, its invalid to use 'path/to/code'? Seems like it defeats the purpose of typescript to append ".js" to the end of every import.

pzimmerman-bmi avatar Dec 11 '25 15:12 pzimmerman-bmi