[Bug]: require of ESM not supported while process.feature.require_module:true
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
hi @everett1992, can you provide a repo for reproduction? There are some missing pieces like Babel config, the project type being CommonJS or ECMAScript, et cetera.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.