question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: ts-jest ignores provided tsconfig.json

See original GitHub issue

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',
    rootDir: './some_root',
    testMatch: [ '**/*.test.ts' ],
    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)

Debug log

TS_JEST_LOG=ts-jest.log node ./node_modules/.bin/jest Produces no output file

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…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
ahnpnlcommented, Jun 20, 2022

Thanks for the information. I think you should report this to Jest since this is out of scope for ts-jest to handle.

0reactions
CyberCookiecommented, Jun 20, 2022

If i create sample file.ts at the root level with the only content: console.log(import.meta)

and run this file with node --loader ts-node/esm ./test.ts - it works okay and produces expected result.

So the issue is definitely in jest scope.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug]: jest ts-node ignores provided tsconfig.json · Issue #12952
Version 28.0.5 Steps to reproduce Create valid jest.config.ts file wit the next content: import { InitialOptionsTsJest } from 'ts-jest' ...
Read more >
Why isn't ts-jest loading my custom tsconfig file? - Stack Overflow
jest.json file is the necessary change to fix my tests because if I make the same change in my main tsconfig.json file my...
Read more >
How to configure Jest with TypeScript | Swizec Teller
This installs jest and ts-jest, TypeScript (if you don't have it yet), and type definitions for jest so TypeScript knows what's available.
Read more >
TSConfig Reference - Docs on every TSConfig option
In this case, TypeScript has provided no warning that download on SharedAlbum ... will look for files starting at the same folder as...
Read more >
Ts-jest-next NPM - npm.io
ts -jest is a TypeScript preprocessor with source map support for Jest ... Modify your project's package.json so that the jest section looks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found