jestjs / jestjs/jest

[Bug]: ESM-CJS interoperability issue of getting incorrectly imported default module

Open
#16,144 11 comments 0 reactions 0 assignees View on GitHub
ES Modules Pinned
Dominant language
TypeScript
Stars
45.5k
Forks
6.7k
Avg merge
17h 22m
Merged PRs (30d)
24

Description

### Version

30.4.1

### Steps to reproduce

Run jest with --experimental-vm-modules on codebase with strongly mixed esm and cjs dependencies.
Upon jest executing this line:
import thunk from 'redux-thunk'

(redux-thunk@2.4.2)

I am getting object like this:
{__esModule: true, default: ƒ}

Instead of default function.

Source of the issue was found within this MR (which created the regression for me): https://github.com/jestjs/jest/pull/16143#discussion_r3207465468

### Expected behavior

I expect thunk variable to contain default function (the same way as is executed in browser handled by webpack/craco), so that my test executes the same way as my browser does

### Actual behavior

thunk is object

### Additional context

_No response_

### Environment

```shell
System:
OS: Windows 11 10.0.22631
CPU: (14) x64 Intel(R) Core(TM) Ultra 5 235U
Binaries:
Node: 24.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - C:\Users\myj\AppData\Roaming\npm\yarn.CMD
npm: 11.12.1 - C:\Program Files\nodejs\npm.CMD
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with Jest 30.4.1 and --experimental-vm-modules using import thunk from redux-thunk@2.4.2; review the regression discussion in PR #16143. Trace the ESM-CJS default import handling, then add coverage showing that thunk is the default function rather than the {__esModule, default} object.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, typescript, webpack
Domain
testing, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.