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
Introducing esm.run - A New-Age CDN for JavaScript modules #18263
Comments
Is there a URL option to bundle all imports inside a single file? Comments in files produced by jsDeliver say that Rollup is used so it won't be a problem. |
Will the current URL scheme change to me more friendly? Currently what I see in devtools/network is bunch of +esm files I guess this Skypack and esm.sh have similar approach for production urls |
@evromalarkey I did notice this problem but you can easily configure devtools to show full paths by right-clicking the column: Alternatively, you could also add the filename as a query string, which we ignore: https://cdn.jsdelivr.net/npm/d3@6.3.1/+esm?d3 |
Congrats on the release! I've run your benchmarks myself a few times now, and can't reproduce your numbers across a few different devices. Here's what I see on my laptop: I don't know if this is out of date or just bad, but the data appears outdated across both Skypack and https://esm.run. Additionally, your benchmark imports are to https://cdn.jsdelivr.net/npm/d3/+esm, and not https://esm.run. That's fine if you want to measure the "optimized" use-case, but then that should really be compared against Skypack's optimized URL as well: https://docs.skypack.dev/skypack-cdn/api-reference/pinned-urls-optimized Can you update these stats to better represent things to your users? |
Hi @FredKSchott, the performance may of course change over time as each of the services develops. We would have preferred showing realtime results but that wasn't possible so we went with numbers that were accurate at the time this was launched. We'll recheck and update if the results are consistently different now. Regarding the pinned URLs, those are not functionally equivalent because they lock down a specific version while jsDelivr (even on our primary domain) and unpkg resolve to latest. |
I'm not sure this is the appropriate place to report this, I've tried this service with Here is a repro: https://vp2177.github.io/js-utils/?jsdelivr-lit-element-issue I have also tried loading |
Thanks for the report @vp2177. I don't immediately see where's the problem as |
@vp2177 after closer inspection we found the problem but not yet sure how we'll be able to fix this. lit-element imports main lit-html file here and it also imports another nested file When we get a request for Then when lib-element imports the main lib-html file in a separate request, it's loaded a second time. This would not be a breaking problem in most cases but the library relies on |
@FredKSchott it seems Skypack is now consistently faster than it was before so we decided to update the numbers. |
https://esm.run/@fullcalendar/daygrid fails to load, you should check all @fullcalendar plugins though, I think it's because import css (eg. https://cdn.jsdelivr.net/npm/@fullcalendar/timegrid/main.js) Another problem is https://esm.run/dayjs (works on https://esm.run/dayjs/esm though) |
Also I see a potential problem with resolving subfolders (only with production url) when using importmaps {
"imports": {
"dayjs": "https://cdn.jsdelivr.net/npm/dayjs/esm/+esm",
"dayjs/": "https://cdn.jsdelivr.net/npm/dayjs/esm/+esm/"
}
}
it would work with esm.run url though {
"imports": {
"dayjs": "https://esm.run/dayjs/esm",
"dayjs/": "https://esm.run/dayjs/esm/"
}
} It would work with |
Yes, that is not supported yet, as mentioned in the original post.
dayjs removed the "module" package.json entry in the recent versions - I'm not sure why but there isn't much we can do in this case. Regarding the import maps - will check this closer. |
Would it be possible to add HTTP2 push support, and an option to disable bundling? With bundling, we get this issue: Imagine having Result:
Bundling is a dinosaur performance thing. We better avoid it when possible. |
@mikabytes indeed, that is basically the issue described in #18263 (comment) and we might end up introducing some options to fix it. |
Hello, I have trouble importing libraries that use import tippy from "https://cdn.jsdelivr.net/npm/tippy.js/+esm"; throws in browser - ReferenceError: process is not defined
- at https://cdn.jsdelivr.net/npm/tippy.js/+esm:12:2691 In skypack, non-production code (including the expression) is stripped away.
vs
Since esm.run is using Rollup, this should be easy to solve with @rollup/plugin-replace plugin (which is also what Tippy suggests). import replace from '@rollup/plugin-replace';
export default {
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}; |
We're aware of this pattern for CJS files but I'd say it's a bad idea to assume Still, if some modules rely on it, we'll look into replacing |
Just a question where did you get that comparison table from? Did you make it using something like photoshop or a service looks nice 👍 |
@MaximKing1 this is regular benchmark results from https://www.jsdelivr.com/esm. You just need to resize your browser's width until the page gets redrawn for smaller devices. |
Found a similar problem in ProposalThere is a suggestion how to solve this problem via
For example, for the above case Perhaps this will be another headache for modules authors , but it will develop people's desire for a thoughtful declaration of dependencies and exported paths for the module. FAQ
|
@IgorNovozhilov the problem is definitely fixable by package authors writing the imports in a different way but our goal is to make as many packages as possible work without requiring specific patterns. |
In this case, if you just add replacement nested file imports to external ones, it will definitely increase the number of packages that will work correctly when importing from your CDN 🙃
|
This is fantastic! May I suggest using |
Thanks for reporting @nihgwu! Turns out we didn't properly purge the old files versions in some cases. This should be fixed soon. |
@MartinKolarik forgot to mention another issue, I got two requests for the same react version, which will cause this error, I double checked the request url is exactly the same, don't know why, unless I explicitly use |
@nihgwu please check now. |
@MartinKolarik thank you for your quick response, really appreciated. It almost works, now I got And this issue is still there, which is the biggest problem for me, I can't use |
I don't follow here, I don't see any duplicate requests in the jsFiddle.
Indeed, I don't see why yet, if you got a chance to pinpoint what exactly is going wrong and where it would greatly help (there's many nested imports so we need to find which file exactly is getting transformed incorrectly if it's supposed to work). |
@MartinKolarik I tried to workaround the dup react issue here, and I think probably you should use the same strategy, and in that way we will get better debug experience, right now they are all
in this way we can ensure only one version of React will be imported You can play with this deployment |
@MartinKolarik Regarding the duplicated requests for React, repro demo in jsFiddle The first and forth requests are importing the same content, and for my case, the request urls are also the same |
@MartinKolarik And for the icon issue, here is the problem, the import result is |
I believe here it would help if you loaded |
The file doesn't have a default export even in the original version so that seems right: https://cdn.jsdelivr.net/npm/@mui/material@5.5.1/utils/index.js Btw we should probably move this to a separate issue, feel free to open one. |
@MartinKolarik in my case the duplicated urls are both
What about my suggestion to response instead of redirecting? That's also what SkypackCDN and esm.sh do |
Indeed, we may need to do the reexport thing for this case. |
Also regarding the paths, there's a reasonable workaround #18263 (comment) but we're still considering other options too. |
Yes I just tested, it's not only for react but any package with a dependent, the dependency will always be requested twice, we should reexport to solve it |
I found issue with Lit lib. https://cdn.jsdelivr.net/npm/lit@2.2.3/+esm https://jsfiddle.net/startweb/ko73cjaq/ File https://cdn.jsdelivr.net/npm/lit-element@3.2.0/lit-element.js/+esm |
When i try to import Here is a cjs example that you can see do not have any but when i add I really dislike that NodeJS added the Buffer module onto the global namespace it the first place... it should have been just like any other core module... ppl should really be using is there any way to circumvent this? i don't want or need the buffer module... |
This is intentional because, unfortunately, many packages rely on the global Buffer and don't work without it. If a global Buffer reference is found it the code, we add the polyfill. |
The package could opt-out from this by using an |
can i (they) do something like
what makes the parse think it needs to polyfill the Buffer? |
Importing it as a module and then adding this to
Alternatively https://nodejs.org/dist/latest-v19.x/docs/api/packages.html#subpath-imports can be used and for browser it can resolve to an empty file.
|
just hope that it don't do minifications first and resolve |
Minification si the last step so that shouldn't be an issue. |
Will the |
Support for dependency version? I am currently aliasing vue and vue-i18n to esm.run
But this will fail, as Of course i could change my dependency to be
Having something like this in |
Playing around with The error I get is:
(Where Is this a bug, or is combining ESM not supported? |
Yes, combine for esm is not supported as it would quite easily result in conflicts in the exports. |
When I try to For clarity, it might be worth adding a similar message that |
I think I have a similar need :
of course I could declare Similarly I cannot import |
Updated as of Sep 2022:
We are excited to announce a long-awaited feature - improved support for packages distributed as ES modules 🎉
It is currently in beta, which means we encourage you to try it out, but not use it in production applications yet. This issue will cover all technical details and can be also used to provide feedback or report bugs if you find any.
TL;DR
https://cdn.jsdelivr.net/npm/uuid/+esm
(default file)https://cdn.jsdelivr.net/npm/uuid/dist/esm-browser/index.js/+esm
(explicit file).https://esm.run/uuid
https://esm.run/uuid/dist/esm-browser/index.js
How this works
Locating entry points
To find the default file, we use
exports
,module
, andjsnext:main
fields frompackage.json
. These fields are currently used by all existing tooling and by most package authors.Handling imports
Resolving
https://example.com/foo
are always kept in their original form.browser
field if it exists (this applies to the entry point as well) and then resolved using node's experimental resolution algorithm, which supports extension resolution and importing from directories that include an index file. The supported extensions are:.mjs
,.js
, and.json
.Bundling
Internal imports (pointing to files in the same package):
import foo from './foo.js'
,import('./foo.js')
.External imports (pointing to files in other packages):
This means that one npm package roughly equals one bundle and one HTTP request, which allows good caching and doesn't require too many HTTP requests.
External URLs are always generated with fully resolved dependency versions based on
package.json
dependencies (or latest if the version is not specified there). This further improves caching and guarantees stable versions even for transitive dependencies.Performance
What doesn't work (but may in the future)
Packages that are written in CJS, or a mix of ESM and CJS.CJS packages are now transformed to ESM.Packages that import core node.js modules.Most core node.js modules are now polyfilled.Packages that import files in formats other than JS/JSON.CSS is now supported too.search on esm.run lists all packages. This will soon be changed to list only the supported ones.The esm.run domain
This domain is introduced as an easier to remember and type alternative. It doesn't run on our multi-cdn architecture and simply redirects all requests to the main cdn domain, so it's not meant to be used in production.
The text was updated successfully, but these errors were encountered: