Skip to content

[Bug]: jest-runtime throws ERR_REQUIRE_ESM with require(esm) pattern #15716

@adalinesimonian

Description

@adalinesimonian

Version

30.0.3

Steps to reproduce

  1. 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"
      }
    }
  2. Create a file that requires the ES module:
    // example.js
    const { serializeError } = require('serialize-error')
    module.exports = { serializeError }
  3. 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
  4. Create a test file that requires the script that requires the ES module:
    // example.spec.js
    const { serializeError } = require('./example.js')
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions