SWC is not adding extension on imports

I’m working with SWC compiler for the first time in a project. I’m using it to compile my typescript files in /src to javascript files in /dist.

The structure of the project is something like this:

| -- demo
     | -- index.html
     | -- index.js
| -- dist
     | -- index.js 
     | -- foo.js
| -- src
     | -- index.ts 
     | -- foo.ts

I was importing foo inside index.ts without the extension import foo from './foo' . The problem is SWC compiled it the same way, without the extension. When I run the demo, it gives an 404 error in the browser, since it can’t find the file.

If I import foo with ‘.ts’ extension, SWC won’t compile it to ‘.js’. A workaround I found is importing ‘foo.js’ though it is ts file.

Is there any configuration to compile ‘.ts’ imports to ‘.js’?

Leave a Comment