-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
new URL() with import.meta.url Fails to Resolve Paths Correctly in Vite 6 #19156
Comments
This was a bug in Vite 5.x. Variables inside To achieve the previous behavior, you can make the split the variable: const t2 = 'login/eraser.png'.split('/');
app.append(new URL(`/src/assets/imgs/${t2[0]}/${t2[1]}`, import.meta.url).href); or use |
There is still a problem. In vite5, the result returned by getImg will match the static resource file name processed by assetFileNames in the vite build configuration, but in vite6, they are not the same, resulting in static resource loading failure. @sapphi-red ,This is my config
|
@lmsccc please create a new issue with a minimal reproduction so we can track your report |
Describe the bug
export function getImg(url: string) { return new URL(
/src/assets/imgs/${url}`, import.meta.url).href;}
const logo = getImg('login/logo.svg');
`
Vite 5 Behavior: The function correctly resolves the path.
Vite 6 Behavior: The function fails to resolve the path correctly.
Reproduction
https://stackblitz.com/edit/vitejs-vite-pqyje2us?file=src%2Fmain.js,package.json&terminal=dev
Steps to reproduce
No response
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: