-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
[Bug]: require of ESM not supported while process.feature.require_module:true #15865
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Description
Version
30.2.0
Steps to reproduce
Jest cannot require esm modules, but it does not override node's process.features.reqiure_module, so code like this will throw an error despite attempts to be defensive.
if (process.features.require_module) {
require("./some-esm.js")
} else {
// some fallback
}
Expected behavior
I expect either require esm to work, or the fallback code path to be executed
Actual behavior
Instead it throws
Must use import to load ES Module
Additional context
As a workaround I can mock the value myself.
beforeEach(() => {
if ("require_module" in process.features) {
jest.spyOn(process.features, "require_module", "get").mockReturnValue(false);
}
})
Environment
System:
OS: Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (14) x64 Intel(R) Core(TM) Ultra 7 165U
Memory: 21.96 GB / 30.79 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 20.19.5 - node
npm: 8.19.4 - npmReactions are currently unavailable