require()
fails to resolve "imports"
map to core module
#51009
Labels
loaders
Issues and PRs related to ES module loaders
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
require('#asdf')
toindex.js
"imports": { "#asdf": "fs" }
topackage.json
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:
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
andrequire()
Just WorkTMIncluding 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!
The text was updated successfully, but these errors were encountered: