-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(jest-runtime): fix node:-prefixed modules loading #11802
fix(jest-runtime): fix node:-prefixed modules loading #11802
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11802 +/- ##
=======================================
Coverage 69.04% 69.04%
=======================================
Files 312 312
Lines 16366 16366
Branches 4746 4747 +1
=======================================
Hits 11300 11300
Misses 5039 5039
Partials 27 27
Continue to review full report at Codecov.
|
Our current behavior matches Node itself, though. $ node -e 'console.log(process.versions.node); require("node:fs")'
14.17.5
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module 'node:fs'
Require stack:
- /Users/simen/[eval]
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at [eval]:1:37
at Script.runInThisContext (vm.js:134:12)
at Object.runInThisContext (vm.js:310:38)
at internal/process/execution.js:81:19
at [eval]-wrapper:6:22
at evalScript (internal/process/execution.js:80:60) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/simen/[eval]' ]
} I don't think Jest should work when it would fail at runtime when you deploy it |
Agree. But the code that I'm trying to test should be loaded with
|
If you use ESM in your tests (https://jestjs.io/docs/ecmascript-modules) it should work already. Does it not? |
Unfortunately, I have TS which is transpiled with |
No luck. "useESM" is applied to the project's own codebase, not its deps. Anyway, I'll do some more experiments. |
That's an issue with |
Hold on. I've removed TS, ts-jest and transforms that could be confusing. Just a pure ESM stand. Take a look: https://github.com/antongolub/jest-issue-11802 |
I seem to have found the source of the problem. Here's the point where ESM flow breaks against the legacy // #289 node_modules/jest-resolve/build/resolver.js
const resolvedModule =
resolveNodeModule(module) || require.resolve(module); Digging notes: https://github.com/antongolub/jest-issue-11802 |
I have the same issue, without typescript as well, it seems to only fail when the |
Oh, thanks for the reply. I really thought that I have the most crooked hands in the world) So even // index.js
import fs from 'node:fs'
console.log('success') is working with a direct @SimenB, |
This comment has been minimized.
This comment has been minimized.
@antongolub thanks for the minimal reproduction 👍 I've opened up a PR fixing it: #11817 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
relates #11331
Hey, @SimenB
Got trouble on loading
node:
-prefixed modules with Node.js 14 and jest v27.1.0:https://github.com/antongolub/tsc-esm-fix/runs/3472541312?check_suite_focus=true
The current impl trims
node:
if the runtime already supports it.I suggest to invert this logic: