Skip to content

Version 22.20.0 tightens Module Loader ? #60290

@mohammedmanna-skyscanner

Description

Version

22.20.0 LTS

Platform

Darwin M-ldkfj2929292 24.6.0 Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:34 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6020 arm64

Subsystem

No response

What steps will reproduce the bug?

before 22.20.0 upgrade, we had 22.17.1 and our script configuration was working correctly.

The line of code (script block, and the affected line respecr) - with 22.17.1

"test": "cd ../../ && jest --verbose --testPathPatterns=packages/platform-tooling"

moduleNameMapper: { '^uuid$': require.resolve('uuid'), ... },

After upgrading to node 22.20.0 - we are seeing the following error stack when that uuid module is being loaded(uuid package version hasn't changed)

`Error: Jest: Failed to parse the TypeScript config file /Users/dumb-user/mockingbird/jest.config.ts

ReferenceError: require is not defined in ES module scope, you can use import instead

at readConfigFileAndSetRootDir (/Users/dumb-user/mockingbird/packages/platform-tooling/node_modules/jest-config/build/index.js:2258:13)

at async readInitialOptions (/Users/dumb-user/mockingbird/packages/platform-tooling/node_modules/jest-config/build/index.js:1147:13)

at async readConfig (/Users/dumb-user/mockingbird/packages/platform-tooling/node_modules/jest-config/build/index.js:918:7)

at async readConfigs (/Users/dumb-user/mockingbird/packages/platform-tooling/node_modules/jest-config/build/index.js:1168:26)

at async runCLI (/Users/dumb-user/mockingbird/packages/platform-tooling/node_modules/@jest/core/build/index.js:1393:7)

at async Object.run (/Users/dumb-user/mockingbird/packages/platform-tooling/node_modules/jest-cli/build/index.js:656:9)`

🤔 Why does this happen? And here is my stupid theory (please rebut and let me know the root cause)

  1. Node v22.20.0 tightened its module loader so a require() on a .ts file now throws ERR_REQUIRE_ESM whenever the file is treated as an ES module. That change comes from the work introducing the native TypeScript loader (--experimental-strip-types) described in the v22.6.0+ release notes on nodejs.org; the loader defaults .ts to ESM, so plain require() is rejected (?)

  2. When Jest tries to load jest.config.ts, it calls require(configPath). Since Node 22.20 reports ERR_REQUIRE_ESM, the code in node_modules/jest-config/build/readConfigFileAndSetRootDir.js falls back to await import(configPath). Inside that ESM evaluation require is not defined, so the line ^uuid$': require.resolve('uuid') immediately throws the “ReferenceError: require is not defined in ES module scope” you’re seeing(?)

Hope this makes sense. And thanks in advance for looking into it.

How often does it reproduce? Is there a required condition?

Immediately after moving from 22.17.1 to 22.20.0

What is the expected behavior? Why is that the expected behavior?

No change in behaviour in any minor/patch version released. Not at least for tightening ESM vs. CJS expectations.

What do you see instead?

As reported above in stack trace.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loadersstrip-typesIssues or PRs related to strip-types support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions