在我的代码中添加环境变量后import.meta.env.VITE_*,使用 vue-test-utils 的测试开始失败,并出现错误:
Jest suite failed to run
error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'.
我已经搜索了一些可用的修复程序,但到目前为止没有一个有效。
编辑
jest.config.js 文件:
module.exports = {
  preset: "ts-jest",
  globals: {},
  testEnvironment: "jsdom",
  transform: {
    "^.+\\.vue$": "@vue/vue3-jest",
    "^.+\\js$": "babel-jest"
  },
  moduleFileExtensions: ["vue", "js", "json", "jsx", "ts", "tsx", "node"],
  moduleNameMapper: {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
      "<rootDir>/tests/unit/__mocks__/fileMock.js",
    "^@/(.*)$": "<rootDir>/src/$1"
  }
}
tsconfig.json 文件:
{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "tests"],
  "compilerOptions": {
    "module": "esnext", …我需要解析通过静态导入或类似函数的动态导入导入的ES 模块,其方式类似于node.js使用require.resolve()解析CJS 模块的方式。ES模块是否存在类似的东西?
例如,如果一个 Vue 包同时具有vue.runtime.common.js和vue.runtime.esm.js. 我需要获得vue.runtime.esm.js. 如果包裹没有,我想知道。