【发布时间】:2020-12-30 11:59:09
【问题描述】:
在我正在处理的一个打字稿项目中,它在节点和浏览器中都运行(使用 html 和 package.json 中的type = 'module)。但是,它不想加载最后没有 .js 扩展名的文件,并且 typescript 正在生成如下所示的文件:
import {foo, bar} from 'threeLetterWords';
此导入在节点和浏览器中均失败,因为它需要找到“threeLetterWords.js”。如何让 TSC 自动将这些 .js 扩展名添加到导入的末尾?
我的`tsconfig.json':
{
"compilerOptions": {
"outDir": "./Build",
"target": "ES6",
}
}
还有我的文件结构:
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
我见过 Typescript compiler is forgetting to add file extensions to ES6 module imports? ,但这个问题是 3 年前提出的,并且 vscode 自动导入是无扩展的,所以我必须手动更改很多(100+)。
有任何进展吗?如果有,如何解决这个问题?
【问题讨论】:
标签: javascript typescript module typescript-compiler-api