Skip to content

mjs module/chunk fetching inconsistent behavior depending on origin #1226

@refi93

Description

@refi93

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";....

Metadata

Metadata

Assignees

No one assigned

    Labels

    browserNot working in Browser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions