开玩笑抛出关于 node_modules 依赖项中的导入的引用错误

问题描述

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

我的 storage.service.ts 在其中一种方法中使用 jimp 来调整图像大小。

这具有依赖于 @jimp/types@jimp/gif 依赖项,而后者依赖于 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": {
    "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": {
...

我怎样才能消除这个错误,或者甚至像修复它一样大胆?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)