[英]jest stop working after setting "type": "module" in tsconfig.json
I am using jest for unit testing in typescript.我在 typescript 中使用 jest 进行单元测试。 When setting "type": "module" in the tsconfig.json, i can run my app, but my jest stops working and say "ReferenceError: require is not defined".
在 tsconfig.json 中设置“type”:“module”时,我可以运行我的应用程序,但我的玩笑停止工作并说“ReferenceError:require is not defined”。
const { pathsToModuleNameMapper } = require("ts-jest/utils");
const { compilerOptions } = require("./tsconfig");
const paths = pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/src" });
delete paths["^(.*)$"];
Eslint is giving me "Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser". Eslint 给我“解析错误:已为 @typescript-eslint/parser 设置了“parserOptions.project”。
I worked around this by specifying a modified duplicate of the main tsconfig.我通过指定主 tsconfig 的修改副本来解决这个问题。
Point to the new file in jest's config:指向 jest 配置中的新文件:
// package.json example
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.test.json"
}
}
}
}
Credit: https://huafu.github.io/ts-jest/user/config/tsConfig信用: https://huafu.github.io/ts-jest/user/config/tsConfig
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.