Skip to content

fix: explicit tsconfig for ts-jest to resolve deprecated moduleResolution - #122

Merged
hzhangxyz merged 2 commits into
mainfrom
copilot/fix-jest-tsconfig-module-resolution
Apr 6, 2026
Merged

fix: explicit tsconfig for ts-jest to resolve deprecated moduleResolution#122
hzhangxyz merged 2 commits into
mainfrom
copilot/fix-jest-tsconfig-module-resolution

Conversation

Copilot AI commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

ts-jest defaults to moduleResolution: node10 when no tsconfig is provided, triggering TS5107 (deprecated, breaks in TypeScript 7.0). The project's tsconfig.json already specifies moduleResolution: bundler—ts-jest just wasn't using it.

Change

  • jest.config.js: Pass tsconfig: "<rootDir>/tsconfig.json" explicitly to the ts-jest transform, so it inherits the project's compiler options instead of falling back to its own deprecated defaults.
// before
"^.+\\.tsx?$": ["ts-jest", { useESM: true }],

// after
"^.+\\.tsx?$": ["ts-jest", { useESM: true, tsconfig: "<rootDir>/tsconfig.json" }],
Original prompt

Create a PR targeting main based on the current Dependabot branch dependabot/npm_and_yarn/npm-dependencies-2a9de1d360 (head SHA 55c4666b14ea45bd854da70afe97856c82bfb1ce).

The GitHub Actions workflow Jest is failing during npm run test with TypeScript error:

  • TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0.

Goal: Apply best practice with minimal file changes (preferably only 1 file) and do not solve by adding ignoreDeprecations.

Proposed fix:

  • Make Jest/ts-jest explicitly use the repository tsconfig to avoid ts-jest/TS6 defaulting to deprecated moduleResolution.
  • Update jest.config.js to pass tsconfig: "<rootDir>/tsconfig.json" in the ts-jest transform options.

Files to inspect/modify:

  • jest.config.js currently:
    export default {
        testMatch: ["<rootDir>/tests/test_*.ts"],
        collectCoverage: true,
        extensionsToTreatAsEsm: [".ts"],
        transform: {
            "^.+\\.tsx?$": ["ts-jest", { useESM: true }],
        },
    };
    Update to include tsconfig option.

Validation:

  • Ensure npm run test passes locally/CI.
  • If specifying the root tsconfig causes tests to fail due to include not covering tests/*, apply the smallest additional change needed (prefer updating tsconfig.json include to add tests). Only do this if required by the test run.

Context:

  • Workflow: .github/workflows/jest.yml runs npm run all on Node 20/22/24.
  • Repo is ESM ("type": "module" in package.json).

Please open the PR with a clear title and description referencing the failing TS5107 error and the fix rationale.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing before any tests run because TypeScript treats a deprecated setting as an error:

TS5107: Option 'moduleResolution=node10' is deprecated ... Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.

This is coming from the TypeScript compiler options being picked up by ts-jest during npm run all (which runs Jest). Even though your repo tsconfig.json shows "moduleResolution": "bundler", the error indicates another tsconfig is being used in the Jest/ts-jest path (commonly tests/tsconfig.json, tsconfig.test.json, or a default ts-jest config), and that config still has moduleResolution: "node10".

Fix (preferred): stop using node10 module resolution in the tsconfig used by tests

  1. Find the tsconfig that Jest/ts-jest is actually using (often configured via globals['ts-jest'].tsconfig or a ts-jest preset).
  2. Change:
"moduleResolution": "node10"

to one of:

"moduleResolution": "node16"

or (if you’re fully ESM/bundler-oriented):

"moduleResolution": "bundler"

This removes the deprecated option entirely, so it will keep working as TypeScript evolves.

Fix (quick unblock): silence the deprecation error

In the tsconfig that currently contains "moduleResolution": "node10", add:

{
  "compilerOptions": {
    "ignoreDeprecations": "6.0"
  }
}

This aligns exactly with the compiler’s instruction in the log and will make CI pass again, but it’s better to also migrate off node10 rather than relying on the ignore.

Optional hardening (make Jest explicitly use the intended tsconfig)

To prevent Jest from accidentally picking up an old/secondary tsconfig, explicitly point ts-jest to your repo tsconfig.json in jest.config.js:

export default {
  testMatch: ["<rootDir>/tests/test_*.ts"],
  collectCoverage: true,
  extensionsToTreatAsEsm: [".ts"],
  transform: {
    "^.+\\.tsx?$": ["ts-jest", { useESM: true, tsconfig: "<rootDir>/tsconfig.json" }],
  },
};

Why this fixes the CI matrix

Your workflow runs Node 20, 22, and 24. Newer TypeScript versions (or stricter defaults in the toolchain) will surface this deprecation as an error across the matrix. Removing node10 (or adding ignoreDeprecations) resolves the compilation step so Jest can actually execute the tests.

User: 用中文回复我,大概发生什么了?

User: 用中文回复我,大概发生什么了?

Assistant: 这次 CI(GitHub Actions 的 Jest job)其实还没开始跑任何测试就挂了,原因是 TypeScript 编译配置里出现了一个已被弃用的选项,并且在你当前的工具链版本下被当成“错误”处理了。

从日志里最关键的一行是:

  • TS5107: Option 'moduleResolution=node10' is deprecated ...
  • 并提示:要么迁移配置,要么加 "ignoreDeprecations": "6.0" 来压掉这个报错

大概发生了什么?

  1. 工作流里跑的是 npm run all(先 build 再 test)。在 test 阶段,Jest 用 ts-jest 去加载并编译你的 tests/*.ts
  2. ts-jest 在编译时会读取某个 tsconfig(TypeScript 配置)。
  3. 这个被读取到的配置里包含了 moduleResolution: "node10"
  4. node10 这种 moduleResolution 现在已经被 TypeScript 标记为 deprecated(弃用),在当前环境中直接报错 TS5107,导致整个 test suite 直接失败(所以你看到 7 个 test 文件都 “Test suite failed to run”,但 Tests: 0)。

为什...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix Jest tsconfig to avoid deprecated moduleResolution fix: explicit tsconfig for ts-jest to resolve deprecated moduleResolution Apr 6, 2026
Copilot AI requested a review from hzhangxyz April 6, 2026 11:13
@hzhangxyz
hzhangxyz marked this pull request as ready for review April 6, 2026 11:15
Copilot AI review requested due to automatic review settings April 6, 2026 11:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hzhangxyz
hzhangxyz merged commit a1a53e1 into main Apr 6, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants