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() fails to resolve "imports" map to core module #51009

Closed
firxworx opened this issue Dec 1, 2023 · 1 comment
Closed

require() fails to resolve "imports" map to core module #51009

firxworx opened this issue Dec 1, 2023 · 1 comment
Labels
loaders Issues and PRs related to ES module loaders

Comments

@firxworx
Copy link

firxworx commented Dec 1, 2023

Version

v20.10.0+

Platform

Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Node is not resolving core modules in imports map when using require()

Steps

  • add require('#asdf') to index.js
  • add "imports": { "#asdf": "fs" } to package.json
  • try running the script with node

The error experienced is:

TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file

Issue History + Stackblitz Repro Links

I initially reported this on tsx as I had assumed fault was with that project vs. Node itself.
The maintainer confirmed this is a Node issue and suggested I report here.

privatenumber/tsx#425

I provided a minimal repro using tsx that impacted the popular (~80M+ weekly) p-limit package v5 vs. v4 where v5 introduced subpath imports:

https://stackblitz.com/edit/node-pqu7ir?file=index.ts

tsx maintainer @privatenumber responded with a minimal repro confirming the issue with require():

https://stackblitz.com/edit/node-cimhvu?file=index.js

He noted:

As a side, it's also worth mentioning that the node: protocol should work there too.

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

Consistently reproducible (refer to stackblitz links)

What is the expected behavior? Why is that the expected behavior?

That import and require() Just WorkTM

Including the case where I hit this: importing from a package that uses subpath imports (in my case in a TypeScript cli that I was executing with tsx -- including with module set to ESNext in tsconfig).

What do you see instead?

TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file

Additional information

I apologize if this is a dupe -- I checked and there appear to be some possibly related issues but I didn't see anything that stuck out to me that was exactly this issue. Thanks for your work on Node!

@firxworx firxworx changed the title require() fails to resolve import map to core module (Node.js bug) require() fails to resolve import map to core module Dec 1, 2023
@aduh95 aduh95 changed the title require() fails to resolve import map to core module require() fails to resolve "imports" map to core module Dec 2, 2023
@aduh95 aduh95 added the loaders Issues and PRs related to ES module loaders label Jan 4, 2024
@aduh95
Copy link
Contributor

aduh95 commented Jan 4, 2024

Duplicate of #49257

@aduh95 aduh95 marked this as a duplicate of #49257 Jan 4, 2024
@aduh95 aduh95 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
loaders Issues and PRs related to ES module loaders
Projects
None yet
Development

No branches or pull requests

3 participants
@aduh95 @firxworx and others