You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Bug]: Jest with ESM enable fails with ENOENT: no such file or directory, open '<<NAME>>' when trying to import a CJS module that re-export a core node module
#13854
Closed
kowalski opened this issue
Feb 3, 2023
· 4 comments
· Fixed by #13856
(node:376068) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/index.test.ts
describe
✓ run main (12 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.653 s
Actual behavior
> [email protected] test
> NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest src/index.test.ts
FAIL src/index.test.ts
● Test suite failed to run
ENOENT: no such file or directory, open 'constants'
at Runtime.readFileBuffer (node_modules/jest-runtime/build/index.js:2316:21)
at Array.forEach (<anonymous>)
at async Promise.all (index 0)
at async Promise.all (index 1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.643 s
Ran all test suites matching /src\/index.test.ts/i.
(node:375769) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Additional context
If you edit node_modules/iso-constants/index.js file like:
I believe that the problem origins in this line: main/packages/jest-runtime/src/index.ts#L954
In here it should be caling this._resolver.isCoreModule(modulePath) and acting accordingly.
@SimenB I've attached a pull request. I tested this using the example repository I've attached and it fixes the problem with a particular package that was giving me a headache.
I wish I knew how to add a testcase for such scenario.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Version
29.4.1
Steps to reproduce
npm i
npm run test
Expected behavior
You should see
Actual behavior
Additional context
If you edit
node_modules/iso-constants/index.js
file like:and re-run the tests, stuff works fine and you the expected output.
I believe that the problem origins in this line: https://github.com/facebook/jest/blob/main/packages/jest-runtime/src/index.ts#L954
In here it should be caling
this._resolver.isCoreModule(modulePath)
and acting accordingly.This is why patching index.js to replace re-export with normal export fixes the problem.
Environment
The text was updated successfully, but these errors were encountered: