-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
import glob, operation not permitted #10306
Comments
This is happening because Vite transforms return new URL(`${subPath}`, import.meta.url).href) into new URL((import.meta.glob("**", { eager: true, import: 'default', as: 'url' }))[subPath], self.location) To workaround this, change |
Build passed, error not showing anymore, but images are not found in production mode I added a
Images path are correct in dev mode (clicking showing them well), but not found in prod mode. prod mode console log |
That behavior is correct. I guess what you want is: <template>
<div>
<img
v-for="(url, key) in imagesUrl"
:key="key"
:src="url"
style="width: 50px; height: 50px"
/>
</div>
</template>
<script setup>
let imagesUrl = import.meta.glob("../assets/images/*.(jpg|JPG|png|PNG|svg)", { as: "url", eager: true });
</script> |
Ok, it is working with import.meta.glob only, but if I still want to use the getImageUrl() for a specific image path, I get the vite import glob operation not permitted again! In the example below, A and B sections works without the other, but not both at the same time!
I think this is the real bug that block me. |
Well I found a workaround that is to write the path and the function like this:
instead of:
I think it can still be considered as a bug, but my problem is solved! Thx a lot @sapphi-red 👍 |
I guess this is what you want: <template>
<div>
<img :src="getImageUrl(path)">
</div>
</template>
<script setup>
let imagesUrl = import.meta.glob("../assets/images/*.(jpg|JPG|png|PNG|svg)", { as: "url", eager: true });
let path = "../assets/images/logo.svg";
function getImageUrl(subPath) {
return imagesUrl[subPath];
}
</script> |
Describe the bug
I am displaying dynamically all images located in the Assets directory. In a SPA with Vue + Vite.
For this purpose, I am using
import.meta.glob("../assets/images/*.(jpg|JPG|png|PNG|svg)", { as: "url" })
,return new URL(`${subPath}`, import.meta.url).href
).Success in dev mode.
Error while building in production mode.
Reproduce
npm run build
Error
Minimal reproductible example
Click to expand!
From a default project vue cli with vite
About.vue
Reproduction
https://github.com/GuillaumeChk/vite-project.git
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: