esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

mjs module/chunk fetching inconsistent behavior depending on origin

Open refi93 opened this issue 2 months ago • 2 comments

Failing module

Looks like caching of modules served from https://esm.sh is behaving inconsistently which results in serving of invalid modules which crash at runtime, examples of inconsistent requests below:

e.g. https://esm.sh/node/path.mjs depending on origin header returns different js

➜  curl 'https://esm.sh/node/path.mjs' -H 'origin: http://localhost:1000' 
import{a,b as s,c as n,d as o,e as i,f as u,g as f,h as m,i as l,j as p,k as c,l as _,m as d,n as v,o as b,p as h,q as y,r as w}from"./chunk-TMXQWSYT.mjs";export{h as _makeLong,p as basename,w as default,d as delimiter,m as dirname,u as extname,l as format,o as isAbsolute,s as join,y as matchesGlob,a as normalize,c as parse,v as posix,f as relative,n as resolve,_ as sep,i as toNamespacedPath,b as win32};

➜  curl 'https://esm.sh/node/path.mjs' -H 'origin: http://localhost:10001'
import{a as t,b as s,c as n,d as o,e as i,f as u,g as f,h as m,i as l,j as p,k as c,l as _,m as d,n as v,o as b,p as h,q as y,r as g,s as w,t as x}from"./chunk-KJ4M6W4Z.mjs";export{g as _makeLong,d as basename,x as default,s as delimiter,c as dirname,l as extname,_ as format,f as isAbsolute,o as join,w as matchesGlob,n as normalize,u as normalizeString,v as parse,y as platform,b as posix,p as relative,i as resolve,t as sep,m as toNamespacedPath,h as win32};

And some chunks even fail to be returned if origin header is passed, which results in crashes at runtime:

➜ curl 'https://esm.sh/node/chunk-WV3DHSZU.mjs' -H 'origin: http://localhost:10002'
Not Found%     

➜ curl 'https://esm.sh/node/chunk-WV3DHSZU.mjs'
import{c as u}from"./chunk-AAUDITJX.mjs";....

refi93 avatar Oct 29 '25 15:10 refi93

i recently updated node polyfills in https://github.com/esm-dev/esm.sh/pull/1225, that might case the issue. i just purged the CDN cache, can you please try again?

ije avatar Oct 29 '25 16:10 ije

Thanks, seems to work fine now 👍

refi93 avatar Oct 29 '25 16:10 refi93