繁体   English   中英

在 tsconfig.json 中设置 "type": "module" 后开玩笑停止工作

[英]jest stop working after setting "type": "module" in tsconfig.json

我在 typescript 中使用 jest 进行单元测试。 在 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 给我“解析错误:已为 @typescript-eslint/parser 设置了“parserOptions.project”。

我通过指定主 tsconfig 的修改副本来解决这个问题。

指向 jest 配置中的新文件:

// package.json example

{
  // [...]
  "jest": {
    "globals": {
      "ts-jest": {
        "tsConfig": "tsconfig.test.json"
      }
    }
  }
}

信用: https://huafu.github.io/ts-jest/user/config/tsConfig

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM