-
-
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
The production environment uses new URL(src, import.meta.url) to report an error #5558
Comments
This is technically not a bug. Vite only supports string or template literals for So either using |
This is because |
So I can understand because of the avoidance of browser compatibility, so it does not support such a way of writing by default, but is it necessary to have additional configuration? Can I add more detailed description at Vite document? Then there will be a more flexible introduction method for img src? |
You can use The only exception is For the documentation, there are already examples shown for that features with string and template literals. So maybe a word of note that Another option is since it already works with template literals, do we also want to work with variables? cc @patak-js for visibility. |
I am very sorry, after I tested again, I found out where the problem is. You can refer to the case of my pass, and the new URL is used inside the component to receive a path. This is no problem in the development environment. It is not the problem of this API, but introduced logo.svg is not packaged to dist / assetsIn the middle, it causes an error, as follows: I am not very clear here, isn't my configuration? import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), vueJsx()],
// publicDir: "/",
resolve: {
alias: {
"@/": new URL("./src/", import.meta.url).pathname,
},
},
}); My technology is very general, still want to ask you, thank you very much. |
@RennCheung An example usage here: https://stackblitz.com/edit/vitejs-vite-yddvqw?file=src/components/HelloWorld.vue |
Ok, trouble, thank you again. |
@ydcjeff the build target has been set |
image is not found |
@ydcjeff Why does vite only support strings? |
I am unsure if this is related but some libraries have now started to use
Is there any way to ensure that I should mention console logging import.meta.url works fine in the source code. May be somewhat related to the comment here https://github.com/jamsinclair/jSquash so going to try the optimizeDeps exclusions. |
This is caused by the esbuild You need to set esbuild target manually here. This issue also happens in development. I wonder if there is any special reason to set default target to |
PR #7279 |
Did you try such Vite config: {
optimizeDeps: {
esbuildOptions: {
target: 'es2020'
}
},
build: {
target: 'es2020'
}
} Still |
According to the error you got #7364 .
I would guess that Vite will search the pattern I would recommend you to change it to a specific file and try it again. I don't think you can actually |
I suggest that Vite check if the URL target is Also, we need to add another warning in the document if this is not fixable. |
Any progress? Scenario: Source production built to: |
Describe the bug
I can display pictures in the development environment, but import.meta.url after packaging is undefined, and cause the New URL to report.
I have already viewed other questions, most of them are previous versions, if it is a duplicate problem or my usage error, then I am very sorry!
Reproduction
https://github.com/RennCheung/import-meta-url-demo
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: