-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Can't require absolute URLs, e.g. from CDN #2421
Comments
The |
Thanks for clarifying that about import jquery from 'https://code.jquery.com/jquery-3.3.1.slim.min.js';
console.log(jquery); |
yeah we currently don't support that since it would require a runtime to actually load and execute the remote module. |
Is the only way to import modules from URLs via dynamic imports? I've submitted a docs PR to mention that (related - #2422). |
Well kinda. That might work for browsers that support dynamic import syntax, but not older ones. Parcel will just ignore dynamic imports of urls, so it won’t work in browsers that don’t support it. |
Right, I should've specified that in the PR. Another problem is that when the library host doesn't set CORS headers, dynamic imports won't work. While I agree this is an issue that should be solved by the library host, are there plans for Parcel to offer an alternative loading method? I've used this successfully: function requireJs(url, module) {
const script = document.createElement('script');
return new Promise(resolve => {
script.src = url;
script.onload = resolve;
if (module) script.type = 'module';
document.head.appendChild(script);
});
} |
Any updates on supporting imports from absolute URLs?
|
|
🐛 bug report
Even after pulling the fix for #2358,
require('https://...cdn_path.../module.min.js')
still fails with:What am I doing wrong? Failing to load CDN libraries seems like a blatant omission.
🎛 Configuration (.babelrc, package.json, cli command)
Zero config.
🤔 Expected Behavior
Server launches.
😯 Current Behavior
🔦 Context
I'm trying to require from CDN a library I don't want to host myself.
💻 Code Sample
index.html:
index.js:
🌍 Your Environment
The text was updated successfully, but these errors were encountered: