In a typescript project I am working on, which runs both on node and in the browser (using the type = 'module
in the html and package.json). However, it doesn't want to load files wihtout the .js extension at the end, and typescript is generating files that look like this:
import {foo, bar} from 'threeLetterWords';
This import fails both in node and in the browser, because it needs to find 'threeLetterWords.js'. How do I make the TSC auto add those .js extensions to the end of the imports?
My `tsconfig.json':
{
"compilerOptions": {
"outDir": "./Build",
"target": "ES6",
}
}
And my file structure:
root
|___Build
| |__(the root directory except for the build folder)
|
|__Public
| |__scripts
| | |__main.js
| | |__threeLetterWords.js
| |__index.html
|
|__Server Logic
| |__threeLetterWordsServer.js
|
|__app.js
|__package.json
|__tsconfig.json
I have seen Typescript compiler is forgetting to add file extensions to ES6 module imports? , but that question was asked 3 years ago, and was vscode auto imports are extension-less, so I would have to change a lot (100+) by hand.
Has any progress been made, and if so what to do to fix this?