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

Subpath imports (require "#foo") do not work in REPL #43410

Closed
mvduin opened this issue Jun 13, 2022 · 0 comments · Fixed by #43450
Closed

Subpath imports (require "#foo") do not work in REPL #43410

mvduin opened this issue Jun 13, 2022 · 0 comments · Fixed by #43450
Labels
repl Issues and PRs related to the REPL subsystem.

Comments

@mvduin
Copy link

mvduin commented Jun 13, 2022

Version

v16.15.1

Platform

Linux bob 5.10.0-12-amd64 #1 SMP Debian 5.10.103-1 (2022-03-07) x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Add a subpath import to package.json, e.g.

"imports": { "#foo": "module-name" }

or

"imports": { "#foo": "./path/to/file.js" }

Then try to import it into the REPL (launched from within your package's directory or subdirectory thereof) using require("#foo") or by passing the -r '#foo' option to node.

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

No response

What is the expected behavior?

I'd expect require() in the REPL to behave as if it was invoked from a source file located in the current directory. This is obviously the most convenient behaviour for debugging, and it's how it works for every other kind of module specifier (including relative paths and exported subpaths of the package).

What do you see instead?

Uncaught Error: Cannot find module '#foo'
Require stack:
- <repl>
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}

Additional information

No response

@F3n67u F3n67u added the repl Issues and PRs related to the REPL subsystem. label Jun 14, 2022
rayw000 added a commit to rayw000/node that referenced this issue Jun 16, 2022
rayw000 added a commit to rayw000/node that referenced this issue Jun 16, 2022
nodejs-github-bot pushed a commit that referenced this issue Jun 30, 2022
PR-URL: #43450
Fixes: #43410
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Jul 12, 2022
PR-URL: #43450
Fixes: #43410
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Jul 31, 2022
PR-URL: #43450
Fixes: #43410
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Oct 10, 2022
PR-URL: nodejs/node#43450
Fixes: nodejs/node#43410
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants