首先,看起来这个问题很复杂。除了 IntelliJ IDEA 和 ts-node 之外,可能是 TypeScript 和 tsx 的问题(看起来 this topic 相关)。目前我不确定bug在哪一边,所以我根据实际看到的情况决定了标题,但看起来只是冰山一角。无论如何,我想,我们不能把所有事情都视为单一问题。
此问题对于
Tests/Automated
下面的所有文件都存在(显然,不仅如此),但我将以 Tests/Automated/Sample.test.ts
文件为例。
此配置文件不涵盖
Tests/Automated/Sample.test.ts
:
{
"compilerOptions": {
"target": "ES2022",
"moduleResolution": "Node",
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"removeComments": true,
"outDir": "Distributable/",
"declaration": true
},
"include": [ "Source/**/*" ]
}
此文件预计涵盖
Tests/Automated/Sample.test.ts
:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext"
},
"include": [ "Tests/**/*" ]
}
IntelliJ IDEA 抱怨
module
和 target
选项错误:
TS1378:仅当模块选项设置为 es2022、esnext、system、node16、nodenext 或preserve,并且目标选项设置为 es2017 或更高版本时,才允许使用顶级等待表达式。
如果尝试运行也会出现同样的错误
ts-node Tests/Automated/Sample.test.ts -p CoreLibrary/Package/tsconfig.test.json
使用完整路径,例如:
import {things} from "folder/file.ts"
things()
使用
ts-node-esm
。
添加到
tsconfig.json
"allowImportingTsExtensions": true,