在提出这个问题之前,我检查了类似的主题并尝试了典型的解决方案。
我知道常见原因是什么"module": "ESXXXX"
在 TypeScript 配置中。
就我而言,我有错误
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\IntelliJ IDEA\XXXXXX\node_modules\tsconfig-paths\src\__tests__\config-loader.test.ts
in both "module": "ESnext"
and "module": "CommonJS"
cases.
典型的解决方案之一是使用ts-节点/esm。
首先,这个功能是实验性的。接下来,它只是将一个错误替换为另一个错误:
(node:24788) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
× ERROR: CustomError: Cannot find module 'D:\IntelliJ IDEA\XXXXX\node_modules\tsconfig-paths\register' imported from D:\IntelliJ IDEA\XXXXX\node_modules\mocha\lib\nodejs\esm-utils.js
Versions
摩卡配置
extension:
- ts
spec: "**/*.test.ts"
require:
- ts-node/register
- tsconfig-paths/register
loader: ts-node/esm # Tried with and without
我使用与您相同的配置,但只有当我降级到 ts-node@9 时它才有效,
然后我在我的中尝试了这个选项.mocharc.json
现在它按我的预期工作了
{
"extensions": ["ts"],
"spec": ["**/*.spec.*"],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)