I have a VueJS project which uses ViteJS to transpile (this works fine) and clearly when ViteJS is involved the resultant output is native ES modules but for Jest testing I was still using ts-jest and my normal old Jest config:
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;
And now suddenly I'm getting this error:
Now this error seems to center around the new import.meta meta-property. This is a new property but I was under the impression that using "ES2020" and "ESNEXT" as a target would allow me to use this. In fact, Vite/Rollup have no problem transpiling this nor does vs-code give me any warnings but between Jest, ts-jest, and Typescript something hasn't given the wrong "target" to the Jest test runner (my tsconfig.json file is correct).
Now I swear, it was working even with this reference to import.meta but somehow now it is not. I'm not sure what in my ENV has changed. Possibly a slightly new node version (I'm using 14.17.6 currently)? Probably a slightly newer version of Typescript (4.4.2 is what I'm using currently).
Anyway, does anyone know how I can get past this?
Note:
- my tsconfig.json reads like this:
{
"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"]
}
