我正在使用 Typescript 构建 NodeJS API,但遇到了如下所示的错误。
坚持了几个小时,我尝试过的所有解决方案都没有奏效。
[ERROR] 22:49:39 ⨯ Unable to compile TypeScript:
src/services/orgService.ts:8:7 - error TS2451: Cannot redeclare block-scoped variable 'organization_1'.
8 const organization_1 = __importDefault(require("../model/organization"));
~~~~~~~~~~~~~~
src/routes/organization.ts:9:7
9 const organization_1 = require("../controller/organization");
~~~~~~~~~~~~~~
'organization_1' was also declared here.
tsconfig
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2018",
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"outDir": "dist",
"types": [
"node"
]
},
"lib": [
"es2018",
"dom"
],
"include": [
"src/**/*",
"typings.d.ts"
],
"exclude": [
"node_modules/",
"**/*.spec.ts",
"dist/",
".vscode"
]
}
此外,似乎每次我改变时,target
例如我得到一个不同的错误。lib
tsconfig