Typescript Ts Jest类型脚本诊断:错误TS2307:找不到模块

Typescript Ts Jest类型脚本诊断:错误TS2307:找不到模块,typescript,vue.js,ts-jest,Typescript,Vue.js,Ts Jest,我在一个包含js和ts文件的vue项目中使用ts jest。项目使用@字符将导入相对映射到目录src/renderer/。TS正在为找不到模块发出警告。我可以通过执行以下操作忽略警告并运行测试: globals: { 'ts-jest': { /* Fails on mapped import syntax without this.*/ diagnostics: { ignoreCodes: ['2307'], }, },

我在一个包含js和ts文件的vue项目中使用ts jest。项目使用
@
字符将导入相对映射到目录
src/renderer/
。TS正在为找不到模块发出警告。我可以通过执行以下操作忽略警告并运行测试:

  globals: {
    'ts-jest': {
      /* Fails on mapped import syntax without this.*/
      diagnostics: {
        ignoreCodes: ['2307'],
      },
    },
  },
但我希望进口能按预期运行

jest.config.js

module.exports = {
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'vue'],
  transform: {
    '^.+\\.js$': '<rootDir>/node_modules/babel-jest',
    '.*\\.(vue)$': 'vue-jest',
    '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    '^.+\\.tsx?$': 'ts-jest',
  },
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/renderer/$1',
    '^vue$': 'vue/dist/vue.common.js',
  },
  roots: ['<rootDir>', '<rootDir>/src/renderer'],
  modulePaths: ['<rootDir>'],
  setupFiles: ['<rootDir>/vue-test-setup.ts'],
  snapshotSerializers: ['jest-serializer-vue'],
  testMatch: ['**/test/**/*.spec.(js|jsx|ts|tsx)|**/__test__/*.(js|jsx|ts|tsx)'],
  transformIgnorePatterns: ['<rootDir>/node_modules/?!(vue-timers)'],
  globals: {
    'ts-jest': {
      /* Fails on mapped import syntax without this.*/
      diagnostics: {
        warnOnly: true,
      },
    },
  },
};

你似乎在某些地方提到了
resources/regex
,在另一些地方提到了
resources/regex
,你确定没有输入错误吗?是的,那是输入错误。。。有趣的是,测试确实在运行时成功。可能问题是您的
tsconfig.json
,然后出现了相同的错误,有机会知道您是如何修复的吗?@y\u nk顶部的globals配置可以选择性地忽略typescript诊断。我在问题中包括了如何忽略诊断。它不能解决问题,但允许运行测试。
 FAIL  test/unit/specs/regexes.spec.ts
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    test/unit/specs/regexes.spec.ts:1:19 - error TS2307: Cannot find module '@/resources/regexes'.

    1 import REGEX from '@/resources/regexes';
                        ~~~~~~~~~~~~~~~~~~~~~