-
-
Couldn't load subscription status.
- Fork 6.6k
Open
Labels
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 - npm