在我的代码中添加环境变量后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'.
Run Code Online (Sandbox Code Playgroud)
我已经搜索了一些可用的修复程序,但到目前为止没有一个有效。
编辑
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"
}
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json 文件:
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "tests"],
"compilerOptions": {
"module": "esnext", …Run Code Online (Sandbox Code Playgroud)