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]: Cause ts error in jest.config.ts when import 'ts-jest'

See original GitHub issue

Version

29.0.1

Steps to reproduce

Here’s my code in jest.config.ts

import type {Config} from 'jest';
import {pathsToModuleNameMapper} from 'ts-jest';

import {compilerOptions} from './tsconfig.json';

const jestConfig: Config = {
  globals: {
    aaa: true
  }, 
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {prefix: '<rootDir>/'})
};

export default jestConfig;

Then the type declare in ts-jest causes the type of globals error: Property ‘‘ts-jest’’ is missing in type ‘’{ aaa: true; }‘’ but required in type ‘ConfigGlobals’.ts(2741) types.d.ts(10, 13): ‘‘ts-jest’’ is declared here.

declare module '@jest/types' {
    namespace Config {
        interface ConfigGlobals {
            'ts-jest': TsJestGlobalOptions;
        }
    }
}

Expected behavior

There shouldn’t be the type error when globals doesn’t contain ‘ts-jest’ since the ts-jest config has been moved to transform.

Actual behavior

The ts type error occurs: Property ‘‘ts-jest’’ is missing in type ‘xxx’(what you write in globals) but required in type ‘ConfigGlobals’.ts(2741) types.d.ts(10, 13): ‘‘ts-jest’’ is declared here.

Debug log

Error: Jest: Failed to parse the TypeScript config file xxxxx/jest.config.ts TSError: ⨯ Unable to compile TypeScript: jest.config.ts:13:3 - error TS2741: Property ‘‘ts-jest’’ is missing in type '{ aaa: true; } but required in type ‘ConfigGlobals’.

Additional context

No response

Environment

System:
  OS: macOS Monterey
Binaries:
  Node: 16.14.2
  pnpm: 6.24.2
npmPackages:
  jest: 29.0.1
  typescript: 4.5.4

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ahnpnlcommented, Sep 15, 2022

Yes:) PR is welcome to fix it

0reactions
crowcccommented, Sep 15, 2022

Yes, so maybe I can expect a new pkg version to solve this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Cannot use import statement outside a module ...
In the end, my jest.config.js looks mainly like this: module.exports = { preset: 'ts-jest/presets/js-with-ts', testEnvironment: "node", ...
Read more >
ts-jest - npm
ts-jest. A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. NPM version NPM downloads ......
Read more >
module ts-jest in the transform option was not found. - You.com | The ...
I am using jest for SPFx project testing. It was working fine but since I have upgraded jest from 24* to 27*, I...
Read more >
Troubleshooting | jest-preset-angular - GitHub Pages
This issue is not related to Jest, it's a known Angular bug ... Define the usage of Babel in Jest config via ts-jest...
Read more >
Testing TypeScript apps using Jest - LogRocket Blog
$ git clone · :ibywaks/cookbook.git ; $ yarn add -D jest @types/jest ts-jest ; # jest.config.ts import type {Config} from '@jest/types'; // Sync ......
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