-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Importing module on filesystem from data URL throws TypeError: Invalid URL
/ ERR_UNSUPPORTED_RESOLVE_REQUEST: Invalid relative URL or base scheme is not hierarchical.
#51956
Comments
TypeError: Invalid URL
Note that Node v21 has slightly better information in its error output:
That said, I'm seeing the same error on Node 18 so probably not a regression, but still definitely a bug. Also note that this cascades: even if you rewrite your own import to a As temporary workaround, I'm currently writing what should be a data-uri to a temporary .js, file and then running an |
TypeError: Invalid URL
TypeError: Invalid URL
/ ERR_UNSUPPORTED_RESOLVE_REQUEST: Invalid relative URL or base scheme is not hierarchical.
@Pomax thanks for letting me know about node 21, I've updated the title to reflect what node 21 prints. I also tried writing a workaround for this using the new module extension API. Could you test it out for your case and see if it's a valid solution? https://www.npmjs.com/package/data-import-fix |
cc @GeoffreyBooth any suggestions on how to fix this? |
@anonrig as a temporary workaround, my solution above seems to work well for me |
Another workaround is to use const module = /* JavaScript */ `
import { createRequire } from "node:module";
const filename = "${import.meta.url}";
const require = createRequire(filename);
require("foo");
`;
import(`data:text/javascript,${module}`); |
A nice find! although a proper fix in Node is still very much required of course. |
Version
v20.11.1
Platform
Linux devbox.home.arpa 6.1.0-16-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.67-1 (2023-12-12) x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Creating an
index.mjs
file with the following contents and running it withnode index.mjs
causes nodejs to be unable to resolve thefoo
module when running in base-64 land.This seems to be because to resolve
foo
we try to loadpackage.json
's, but it seems like we're trying to do it from the data URL, which can't work.How often does it reproduce? Is there a required condition?
You should run this code somewhere where it's safe to create a new
node_modules
.Running the code always produces the same result on macOS and Linux. Untested on Windows.
What is the expected behavior? Why is that the expected behavior?
Either:
I think either this shouldn't try to do this and should error explicitly that it's not supported, or it should work if it's within scope/spec. I'd argue an internal error saying the URL is invalid (when both package.json and the data URL are valid) is confusing here for most nodejs developers.
What do you see instead?
Additional information
Potentially related to #51444 and #38714
Potentially related to subsystems:
@nodejs/loaders @nodejs/modules
Workaround: https://github.com/benjamingwynn/data-import-fix
The text was updated successfully, but these errors were encountered: