-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Open
Labels
Description
Version
30.0.3
Steps to reproduce
- Create a CommonJS package with a dependency on Jest and some ESM package that has no top-level await. For example:
{ "name": "jest-repro", "version": "1.0.0", "type": "commonjs", "main": "example.js", "scripts": { "test": "jest" }, "dependencies": { "jest": "^30.0.3", "serialize-error": "^12.0.0" } }
- Create a file that requires the ES module:
// example.js const { serializeError } = require('serialize-error') module.exports = { serializeError }
- Verify the script does not error out in your version of Node.js. If it does, you may need to switch to at least Node.js 23.0.0, 22.12.0, or 20.19.0, for this to work without needing to pass
--experimental-require-module
.node example.js
- Create a test file that requires the script that requires the ES module:
// example.spec.js const { serializeError } = require('./example.js')
- Run Jest.
npm test
Expected behavior
There is no error, as the ES module can successfully be required.
Actual behavior
jest-runtime throws its own ERR_REQUIRE_ESM
error and fails the test.
Additional context
This feature is now a release candidate and no longer experimental, so it seems reasonable to expect that this should not be causing errors anymore in Jest.
Environment
System:
OS: Linux 6.15 Fedora Linux 42 (Workstation Edition)
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-1280P
Binaries:
Node: 24.3.0 - ~/.volta/tools/image/node/24.3.0/bin/node
npm: 11.4.2 - ~/.volta/tools/image/node/24.3.0/bin/npm
npmPackages:
jest: ^30.0.3 => 30.0.3