This is a demo code below used to demonstrate failure i am getting in my current project.
It tanspiles and runs, just fails to compile with jest with following error
Error: error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
Files: src/calc.ts
import { fileURLToPath } from 'url'; import path from 'path'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); export function add(x: number, y: number): number { return x + y; } export function mul(x: number, y: number): number { return x * y; } jest.config.cjs:
module.exports = { preset: 'ts-jest', testEnvironment: 'node', }; tsconfig.json:
{ "include": [ "./src/**/*" ], "exclude": [ "node_modules" ], "compilerOptions": { "target": "ES2022", "module": "NodeNext", "outDir": "./out", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true } } package.json
"devDependencies": { "@types/jest": "^26.0.24", "jest": "^26.6.3", "ts-jest": "^26.5.6", "typescript": "^4.7.4" } Not sure if i am doing anything incorrect here
--moduleis not a jest CLI option?