我对已编译的打字稿代码有疑问。我在 package.json 中使用需要 "type": "module" 选项的外部包,否则会引发错误。由于需要此选项,因此我以这种方式编辑我的 tsconfig:
{
"compilerOptions": {
"target": "es2015",
"module": "es2020",
"lib": ["DOM","ES2017","es5"],
"outDir": "./build",
"removeComments": true,
"moduleResolution": "node",
"baseUrl": "./src",
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src/**/*"
]
}
但编译后的代码告诉我未定义导出
exports.__esModule = true;
ReferenceError: exports is not defined
我已经尝试过:
- 将 es5 导入为库
- 将 tsconfig 模块更改为 es2015,commonjs(废话,但我试过了)
- 将 tsconfig 目标更改为 es2017、es2015、es2020
- 安装模块 common-js
这一切都不起作用