ES ModulesHelp WantedPinnedTypeScript
Description
Version
28.0.5
Steps to reproduce
Create valid jest.config.ts file wit the next content:
import { InitialOptionsTsJest } from 'ts-jest'
import path from 'path'
console.log(import.meta)
const jestOptions: InitialOptionsTsJest = {
preset: 'ts-jest/presets/default-esm',
rootDir: './some_root',
testMatch: [ '**/*.test.ts' ],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
},
globals: {
'ts-jest': {
useESM: true,
tsconfig: path.join(process.cwd(), 'tsconfig.json')
}
}
}
export default jestOptions
Note console.log(import.meta)
Create valid tsconfig.json file:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"allowJs": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true
}
}
run npx jest
Expected behavior
No TS errors
Actual behavior
Error: Jest: Failed to parse the TypeScript config file ./some_proj/jest.config.ts
TSError: ⨯ Unable to compile TypeScript:
jest.config.ts:55:13 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'.
console.log(import.meta)
~~~~~~~~~~~
at readConfigFileAndSetRootDir (/some_proj/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:136:13)
at async readConfig (/some_proj/node_modules/jest-config/build/index.js:216:18)
at async readConfigs (/some_proj/node_modules/jest-config/build/index.js:404:26)
at async runCLI (/some_proj/node_modules/@jest/core/build/cli/index.js:140:59)
at async Object.run (/some_proj/node_modules/jest-cli/build/cli/index.js:155:37)
Additional context
No response
Environment
System:
OS: Linux 5.17.12-100.fc34.x86_64
CPU: (8) arm64
Binaries:
Node: 16.15.0
npm: 7.20.0
npmPackages:
"jest": "28.1.0",
"ts-jest": "^28.0.5"
Stack overflow
There is a question on stackoverflow been posted 9 months ago still not answered...