[Bug?]: ERR_MODULE_NOT_FOUND with Yarn 4.6.0
envgap__yarnpkg__berry-6646
Original GitHub issue ↗Opened 2025-01-06
01 / FAILURE SIGNATURE
As reported upstream
4. Observe error:
Not a benchmark task.
- No curated issue-specific recipe or verified environment fix is available.
02 / ENVIRONMENT RECIPE
- Base commit
Not freshly verified- Manifest
package.json- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
yarnpkg/berry #6646 · read the original issue
### Self-service
- [x] I'd be willing to implement a fix
### Describe the bug
Module resolution fails for some combination of CJS and ESM as of Yarn 4.6.0. It works when using Yarn 4.5.3 or npm (with both Node 22.12.0 and Node 22.11.0).
### To reproduce
1. Clone https://github.com/Methuselah96/test-jest
2. Run `yarn install`
3. Run `yarn test`
4. Observe error:
```
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'babel-jest' imported from C:\Users\nbier\Documents\test-jest\jestTransformer.js
Did you mean to import "babel-jest/build/index.js"?
at packageResolve (node:internal/modules/esm/resolve:857:9)
at moduleResolve (node:internal/modules/esm/resolve:926:18)
at defaultResolve (node:internal/modules/esm/resolve:1056:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:654:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:603:25)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:353:53)
at new ModuleJobSync (node:internal/modules/esm/module_job:341:34)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:326:11)
at loadESMFromCJS (node:internal/modules/cjs/loader:1414:24)
at Module._compile (node:internal/modules/cjs/loader:1547:5)
```
### Environment
```shell
System:
OS: Windows 11 10.0.26100
CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13500
Binaries:
Node: 22.12.0 - ~\AppData\Local\Temp\xfs-d16ac07e\node.CMD
Yarn: 4.6.0 - ~\AppData\Local\Temp\xfs-d16ac07e\yarn.CMD
npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD
bun: 1.1.0 - ~\.bun\bin\bun.EXE
```
### Additional context
_No response_04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]
Issue-specific recipe and runtime smoke command require review against the complete issue and repository.
Legacy reproduction is generic install-only; match the actual issue failure before admission.