-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
“Failed to construct 'URL': Invalid URL” in v2.9.1 #7647
Comments
After Set build-target and optimizedeps.esbuildoptions.target to |
Hello @JackieCheung. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
I have the same bug in vite@2.8.4 and vite@2.7.13.After building,import.meta is empty object. |
In my case, everything was good before version @2.8.6, this problem occurs after upgrading to @2.9.1. Refer to this PR although set |
I made a reproduction https://stackblitz.com/edit/vitejs-vite-viades?file=src%2Fmain.ts&terminal=dev. Run |
Thank you for your reproduction. I have updated my comment. |
Can confirm - having the same issue 😢 |
I'm in the same boat. How do you solve it ? 😢 |
change to use dynamic import, such as
or change to not use template string, such as
Hope to help you. |
Your answer was a great help to me. Thank you so much ! 👍 |
Describe the bug
After upgrading to vite@2.9.1,
new URL
andimport.meta.URL
was failed.It occurred an error as
Uncaught TypeError: Failed to construct 'URL': Invalid URL
.The
src
of img cannot be inferred correctly. But in vite@2.8.6 everything went well.used in .ts
<img src="${new URL("/front/assets/loading.c075df69.gif",self.location).href}" alt=''>
The
src
of img is"http://192.168.1.159/front/assets/loading.c075df69.gif"
which is correct<img src="${new URL("../assets/images/loading/loading.gif",Jo.url).href}" alt=''>
Reproduction
https://stackblitz.com/edit/vitejs-vite-viades?file=src%2Fmain.ts&terminal=dev.
Run
npm run build && npm run preview
, the first image asset can't be found as import.meta.url is in the template string.System Info
Used Package Manager
pnpm
Logs
Uncaught TypeError: Failed to construct 'URL': Invalid URL
Validations
The text was updated successfully, but these errors were encountered: