Skip to content
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

require throws, but require.resolve does not #43274

Closed
ljharb opened this issue Jun 1, 2022 · 4 comments · Fixed by #43336
Closed

require throws, but require.resolve does not #43274

ljharb opened this issue Jun 1, 2022 · 4 comments · Fixed by #43336
Labels
confirmed-bug Issues with confirmed bugs. module Issues and PRs related to the module subsystem.

Comments

@ljharb
Copy link
Member

ljharb commented Jun 1, 2022

Version

16.15.0

Platform

Darwin computername.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64 x86_64

Subsystem

node:readline/promises

What steps will reproduce the bug?

  1. run node -pe "require.resolve('readline/promises2')" and node -pe "require('readline/promises2')". Observe that both throw.
  2. run node -pe "require('node:readline/promises')". Observe that it throws "no such builtin module".
  3. run node -pe "require.resolve('node:readline/promises')" or node -pe "require.resolve('node:readline/promises2'), and instead of throwing, both print the given specifier.

Modules that are not requireable must NEVER be require.resolveable; that's part of the contract of require.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

See above.

Additional information

No response

@ljharb ljharb added the module Issues and PRs related to the module subsystem. label Jun 1, 2022
@ljharb
Copy link
Member Author

ljharb commented Jun 1, 2022

cc @nodejs/modules

@ljharb
Copy link
Member Author

ljharb commented Jun 1, 2022

Note: this also seems to be the case in node 14, but not 18. (update: in resolve's tests, but see below; apparently it is broken in node 18)

@ljharb ljharb changed the title require('node:readline/promises') fails in node 16, but require.resolve does not require fails in node 14 and 16, but require.resolve does not Jun 1, 2022
@aduh95
Copy link
Contributor

aduh95 commented Jun 1, 2022

Note: this also seems to be the case in node 14, but not 18.

I'm able to reproduce on both v18.x and master:

$ node -pe 'require.resolve("node:readline/promises2")'
node:readline/promises2
$ out/Release/node -pe 'require.resolve("node:readline/promises2")'
node:readline/promises2
$ out/Release/node -pe 'require("node:readline/promises2")'       
node:internal/modules/cjs/loader:790
      throw new ERR_UNKNOWN_BUILTIN_MODULE(filename);
      ^

Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: node:readline/promises2
    at new NodeError (node:internal/errors:388:5)
    at Module._load (node:internal/modules/cjs/loader:790:13)
    at Module.require (node:internal/modules/cjs/loader:1008:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:76:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60) {
  code: 'ERR_UNKNOWN_BUILTIN_MODULE'
}

Node.js v19.0.0-pre

@aduh95 aduh95 added confirmed-bug Issues with confirmed bugs. and removed v14.x labels Jun 1, 2022
@aduh95 aduh95 changed the title require fails in node 14 and 16, but require.resolve does not require throws, but require.resolve does not Jun 1, 2022
@ljharb
Copy link
Member Author

ljharb commented Jun 1, 2022

oh hm, thanks for confirming. the resolve tests didn't fail on node 18, oddly enough.

Either way, this feels like a sizable bug with the node: protocol. It would be ideal to get a fix for this landed and backported as far back as possible (14).

zhmushan added a commit to zhmushan/node that referenced this issue Jun 7, 2022
zhmushan added a commit to zhmushan/node that referenced this issue Jun 7, 2022
zhmushan added a commit to zhmushan/node that referenced this issue Jun 7, 2022
zhmushan added a commit to zhmushan/node that referenced this issue Jun 7, 2022
aduh95 pushed a commit that referenced this issue Jun 17, 2022
Fixes: #43274

PR-URL: #43336
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Jul 12, 2022
Fixes: #43274

PR-URL: #43336
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Jul 31, 2022
Fixes: #43274

PR-URL: #43336
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Oct 10, 2022
Fixes: nodejs/node#43274

PR-URL: nodejs/node#43336
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
abhishekumar-tyagi pushed a commit to abhishekumar-tyagi/node that referenced this issue May 5, 2024
Fixes: nodejs/node#43274

PR-URL: nodejs/node#43336
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants