-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
HTTPS imports fail for relative URLs #42098
Comments
From this error, it seems the loader doesn't support relative URL references yet, which would mean it won't work with... almost anything 🤔 Or maybe it's the |
@nodejs/modules |
This looks like a bug with |
I'm working on a fix (for https modules that contain relative imports) |
This may be obvious, but putting it here in case it isn't: even if relative imports worked, |
|
So does jsDelivr, |
A fix would be something like: index 61e609d9ad..d0579e5e5b 100644
--- a/lib/internal/modules/esm/loader.js
+++ b/lib/internal/modules/esm/loader.js
@@ -574,11 +574,12 @@ class ESMLoader {
);
}
- new URL(url); // Intentionally trigger error if `url` is invalid
+ // Error early and resolve base urls for https imports
+ const withParent = new URL(url, parentURL);
return {
format,
- url,
+ url: withParent.href,
};
Note @MartinKolarik that https://cdn.jsdelivr.net/npm/[email protected]/wrapper.mjs/+esm returns a 404 so I wasn't able to test that with the patch. (Edit: note a real patch would also include fixing local imports that is fixing checkIfDisallowedImport ) |
Thanks for the ping, I forgot it now enforces the |
Yeah, that returns:
With the patch but at least it loads the package. |
👍 we'll tweak the jsDelivr behavior to support the first link in the next few days. |
can we get confirmation to close this? It should be fixed now that the PR is closed and 17.7.0 is released. I'd note that the unpkg URL still fails due to referencing a URL that is a 404 though, node can't fix that one. |
Confirmed fixed on 17.7.1. It will still fail due to the import { v4 as uuidv4 } from 'https://cdn.jsdelivr.net/npm/[email protected]/wrapper.mjs/+esm';
console.log(uuidv4()); |
Hi this is slightly unrelated but figured I would post it here in case anyone else finds this thread like I did. In my case I was getting the same error |
import fetch from 'https://cdn.jsdelivr.net/npm/node-fetch/+esm'
const run = async () => {
...
}
run()
Slightly related. |
Details
Part of the goal of the network import feature for ECM is that I should be able to load a module hosted via any HTTPS location, like for example common CDNs for hosting such modules such as https://esm.run or https://unpkg.com.
For example, the popular
uuid
package claims it's an ESM:It is hosted in the various CDNs:
Yet, none of these work when trying to load with the new network imports, see snippet.
Node.js version
17.5 with --experimental-network-imports
Example code
Example:
Output:
Another example
Output:
Operating system
MacOS 12.1
Scope
Runtimne
Module and version
Not applicable.
The text was updated successfully, but these errors were encountered: