Jestjs Jest抛出有关节点\模块依赖项内导入的引用错误

Jestjs Jest抛出有关节点\模块依赖项内导入的引用错误,jestjs,nestjs,nestjs-testing,Jestjs,Nestjs,Nestjs Testing,我有一个nestjs monorepo应用程序,通过Jest进行工作测试。这与全局单元测试有关,全局单元测试从package.json中的nestjs CLI创建的配置中获取配置 My storage.service.ts在其方法之一中使用jimp调整图像大小 它具有依赖于依赖于@jimp/gif的@jimp/types依赖关系,后者依赖于gifwrap 对于在我的控制台中运行的每个测试,我都会看到以下错误: ReferenceError: You are trying to `import`

我有一个nestjs monorepo应用程序,通过Jest进行工作测试。这与全局单元测试有关,全局单元测试从package.json中的nestjs CLI创建的配置中获取配置

My storage.service.ts在其方法之一中使用
jimp
调整图像大小

它具有依赖于依赖于
@jimp/gif
@jimp/types
依赖关系,后者依赖于
gifwrap

对于在我的控制台中运行的每个测试,我都会看到以下错误:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

      at node_modules/.pnpm/gifwrap@0.9.2/node_modules/gifwrap/src/gifcodec.js:7:15
我还使用beforeAll()和afterAll()钩子来关闭nestjs模块

Jest配置:

  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": ".",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "./coverage",
    "testEnvironment": "node",
    "roots": [
      "<rootDir>/apps/",
      "<rootDir>/libs/"
    ],
    "moduleNameMapper": {
...
“开玩笑”:{
“moduleFileExtensions”:[
“js”,
“json”,
“ts”
],
“rootDir”:“,
“testRegex”:“*\\.spec\\.ts$”,
“转变”:{
“^.+\.(t|j)s$”:“ts笑话”
},
“CollectionCoverage from”:[
“***(t|j)s”
],
“coverage目录”:“/coverage”,
“测试环境”:“节点”,
“根”:[
“/apps/”,
“/libs/”
],
“moduleNameMapper”:{
...

我怎样才能消除这个错误,甚至可以大胆地修复它呢?

你解决了这个问题吗?这个人运气好吗?遗憾的是,没有,我相信降级到另一个typescript版本,特别是
4.0.6
并使用
warn
而不是
pnpm
暂时解决了这个问题,但不是一个永久的解决方案