You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// fsRoot is set to "C:/" when on WindowsconstfsRoot=os__default.platform()=='win32' ? process.cwd().split(path__default.sep)[0]+'/' : '/';constserveFromRoot=sirv(fsRoot,sirvOptions);return(req,res,nexT)=>{consturl=req.url// url is "/@fs/C:/path/to/file.ext"if(url.startsWith(FS_PREFIX)){// req.url is now "C:/path/to/file.ext"req.url=decodeURI(url.slice(FS_PREFIX.length));// tries to serve "C:\C:\path\to\file.ext" (note the duplicate C:\ prefix)// because serveFromRoot JOINS fsRoot with the url. This is incorrect on Windows,// since fsRoot is not "/".serveFromRoot(req,res,next);}}functionviaLocal(dir,isEtag,uri,extns){leti=0,arr=toAssume(uri,extns);letabs,stats,name,headers;for(;i<arr.length;i++){abs=path$1.normalize(path$1.join(dir,name=arr[i]));// <---- Join happens hereconsole.log(abs)// <-------------------------------------------- Observe incorrect path hereif(abs.startsWith(dir)&&fs$2.existsSync(abs)){stats=fs$2.statSync(abs);if(stats.isDirectory())continue;headers=toHeaders(name,stats,isEtag);headers['Cache-Control']=isEtag ? 'no-cache' : 'no-store';return{ abs, stats, headers };}}}
Proposed Fix
I've explored two fixes for this, both of which solve the problem on my end:
Strip fsRoot from the requested URL if fsRoot is not /
Replace path.join() with path.resolve() in the viaLocal function
I hesitated from sending a PR because I wondered if you had a preferred approach or if I was overlooking anything, i.e. is it even necessary to have fsRoot be C:/ on Windows? If you can let me know your thoughts, I would be happy to open up a PR to address this.
Describe the bug
When importing an asset that is outside of root, vite returns the absolute path to that file. This path is not served properly by the development server when on Windows because the path is incorrectly joined to
fsRoot
. The issue has to do with these lines in https://github.com/vitejs/vite/commits/main/packages/vite/src/node/server/middlewares/static.ts:Proposed Fix
I've explored two fixes for this, both of which solve the problem on my end:
fsRoot
from the requested URL iffsRoot
is not/
I hesitated from sending a PR because I wondered if you had a preferred approach or if I was overlooking anything, i.e. is it even necessary to have
fsRoot
beC:/
on Windows? If you can let me know your thoughts, I would be happy to open up a PR to address this.Reproduction
https://github.com/davezuko/reproductions/tree/master/vite-1982
System Info
vite
version: 2.0.0-beta.67 and 2.0.0-beta.68The text was updated successfully, but these errors were encountered: