Currently, I am working on a VueJS project that utilizes ViteJS for transpilation, which is functioning properly. However, when Jest testing is involved alongside ts-jest, the following Jest configuration is used:
jest.config.ts
import { resolve } from "path";
import type { Config } from "@jest/types";
const config: Config.InitialOptions = {
verbose: true,
testEnvironment: "jsdom",
// roots: ["tests", "src"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testPathIgnorePatterns: ["/node_modules/"],
moduleNameMapper: {
"^[/]{0,1}~/(.*)$": resolve(process.cwd(), "src", "$1"),
},
testMatch: ["**/?(*[-.])+(spec|test).ts"],
setupFilesAfterEnv: ["jest-extended"],
};
export default config;
Recently, an error has started to occur:
https://i.stack.imgur.com/gSOTE.png
The error appears to be related to the new meta-property import.meta
. Despite setting the target as "ES2020" and "ESNEXT" in my tsconfig.json file, it seems like there might be an issue with how Jest, ts-jest, and Typescript are handling this property.
Previously, everything was working fine even with references to import.meta
, but now it seems to have stopped functioning correctly. I suspect it might be due to changes in my environment, such as a newer version of Node (currently using v14.17.6) or Typescript (using v4.4.2).
If anyone has any insights on how to resolve this issue, I would greatly appreciate it.
Note:
- The contents of my tsconfig.json are as follows:
{
"compilerOptions": {
"module": "ES2020",
"target": "ESNext",
"lib": ["DOM", "ESNext"],
"strict": true,
"esModuleInterop": true,
"incremental": true,
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"declaration": true,
"outDir": "dist",
"paths": {
"~/*": ["src/*"]
},
},
"include": ["src", "test"],
"exclude": ["dist", "node_modules"]
}