Search code examples
javascriptnode.jstypescriptmoduletsconfig

Add .js extension on TypeScript build


If I import a file import * as test from './dir/file', the .js extension is missing in the build

I want the output file like this import * as test from './dir/file.js'

The problem is: YES I can add the .js manually BUT many libraries doesn't have the .js extension manually added, and I don't want to go through all files of a library and add the extension manually.

And I know there are some regex replacer out there which add the .js extension. But is this the only way?? Is there no way to tell TypeScript to add the .js (maybe via tsconfig.json)???


Solution

  • There is a github issue opened about this, check it out here for workarounds, as I don't think it is possible with current ts compiler.