In the code snippet below, I am showcasing a problem that I am currently facing in my project.
The code transpires and executes, but it fails to compile with jest due to the 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"
}
I'm not certain if I'm making any mistakes here.