-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
loader: require.resolve should throw for unknown builtin modules #43336
Conversation
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for fixing this!
s/unkonw/unknown/ in commit message |
Can you explain in detail what this means? I'm not very familiar with the nodejs contribution requirements. |
It just means there is a typo in your commit message "unkonw" that should be "unknown". |
Oh, thank you very much. I just realized it was a vim shortcut, forgive me for not knowing anything about it. |
() => require.resolve('node:unknown'), | ||
{ | ||
code: 'MODULE_NOT_FOUND', | ||
message: /^Cannot find module 'node:unknown'/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote from the documentation:
If the module can not be found, a MODULE_NOT_FOUND error is thrown.
@@ -780,19 +780,19 @@ Module._load = function(request, parent, isMain) { | |||
} | |||
} | |||
|
|||
const filename = Module._resolveFilename(request, parent, isMain); | |||
if (StringPrototypeStartsWith(filename, 'node:')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading a builtin module prefixed with "node:" expects "ERR_UNKNOWN_BUILTIN_MODULE" to be thrown.
If the "resolve" function is called here, "MODULE_NOT_FOUND" will be thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERR_UNKNOWN_BUILTIN_MODULE
certainly makes more sense here than MODULE_NOT_FOUND
, I agree (although I think both are fine).
Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
LGTM |
This comment was marked as outdated.
This comment was marked as outdated.
Commit Queue failed- Loading data for nodejs/node/pull/43336 ✔ Done loading data for nodejs/node/pull/43336 ----------------------------------- PR info ------------------------------------ Title loader: require.resolve should throw for unknown builtin modules (#43336) Author 木杉 (@zhmushan) Branch zhmushan:require_resolve -> nodejs:master Labels module, author ready, needs-ci Commits 3 - loader: make require.resolve throw error for unknown builtin modules - Update lib/internal/modules/cjs/loader.js - Update test/parallel/test-require-resolve.js Committers 2 - 木杉 - GitHub PR-URL: https://github.com/nodejs/node/pull/43336 Fixes: https://github.com/nodejs/node/issues/43274 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Luigi Pinca ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/43336 Fixes: https://github.com/nodejs/node/issues/43274 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Luigi Pinca -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 07 Jun 2022 04:12:07 GMT ✔ Approvals: 4 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/43336#pullrequestreview-999163419 ✔ - Benjamin Gruenbaum (@benjamingr): https://github.com/nodejs/node/pull/43336#pullrequestreview-1000924532 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/43336#pullrequestreview-1003513209 ✔ - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/43336#pullrequestreview-1006496775 ✖ Last GitHub CI failed ℹ Last Full PR CI on 2022-06-13T16:59:06Z: https://ci.nodejs.org/job/node-test-pull-request/44498/ - Querying data for job/node-test-pull-request/44498/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/2497846390 |
Landed in 7fd4cf4 |
Yay! What’s the best way to quickly backport this as far as possible? |
Fixes: #43274 PR-URL: #43336 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Fixes: #43274 PR-URL: #43336 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Fixes: nodejs/node#43274 PR-URL: nodejs/node#43336 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Fixes: nodejs/node#43274 PR-URL: nodejs/node#43336 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Fixes: #43274