Skip to content

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

@mvduin

Description

@mvduin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions