Skip to content
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

Monorepo on Windows can't serve static assets imported from a different drive #12816

Closed
7 tasks done
nz771202 opened this issue Apr 10, 2023 · 2 comments
Closed
7 tasks done

Comments

@nz771202
Copy link

Describe the bug

I'm developing a monorepo that imports different packages that may be on different windows volumes. Some of the packages try to load images but fail when the vite root is on a different volume. However, if I move all packages to the same drive, everything works fine.

Example of error message in the browser's console:

GET http://127.0.0.1:5173/@fs/d:/subrepo/image.png 404 (Not Found)

Error message with --debug:

vite:html-fallback Not rewriting GET /%2Fsubrepo2%2Fimage.png because the path includes a dot (.) character. +72ms

Reproduction

You need a windows machine with multiple drive letters. I'm providing a simple example below.

Steps to reproduce

1. Create the following files and folders:

d:\subrepo\index.ts:

import imgUrl from "./image.png";
export default function() {
    const img = new Image();
    img.src = imgUrl;
    document.body.appendChild(img);
}

c:\mainrepo\index.ts:

import test from "d:/subrepo";
test();

c:\mainrepo\index.html:

<!DOCTYPE html>
<html lang="en">
    <body><script type="module" src="index.ts"></script></body>
</html>

Also put an arbitrary image as "image.png" into d:\subrepo.

You should have the following folders and files:

c:\mainrepo:
    index.ts
    index.html
d:\subrepo:
    image.png
    index.ts

2. In c:\mainrepo run the commands:

npm i vite
npx vite

3. Visit 127.0.0.1:5173

Try it also with the two folders on the same drive.

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 AMD Ryzen 5 5600H with Radeon Graphics
    Memory: 9.42 GB / 15.36 GB
  Binaries:
    Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1413.0), Chromium (112.0.1722.34)
    Internet Explorer: 11.0.22621.1

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

Vite doesn't support this yet because Vite relies on sirv.

let newPathname = pathname.slice(FS_PREFIX.length)
if (isWindows) newPathname = newPathname.replace(/^[A-Z]:/i, '')
url.pathname = encodeURI(newPathname)
req.url = url.href.slice(url.origin.length)
serveFromRoot(req, res, next)

@sapphi-red
Copy link
Member

I'll merge this issue to #10802

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants