image: IPX: File not found when using assets directory
I’m using Nuxt 3.7.3, Nuxt image 1.0.0-rc.2
In a component, providing image from assets directory as src prop of <NuxtImg> does not render image, I see “404 IPX: File not found” error in JS console.
Same image with <img> tag works correctly.
This works:
<img src="~/assets/img/banners/front-page-banner.png" alt="Banner" />
This does not work:
<NuxtImg src="~/assets/img/banners/front-page-banner.png" alt="Banner" />
Import also does not work. This does not work:
<script lang="ts" setup>
import banner from '~/assets/img/banners/front-page-banner.png';
</script>
<template>
<NuxtImg :src="banner" alt="Banner" />
</template>
According documentation https://image.nuxt.com/get-started/configuration#dir I’ve added assets directory to nuxt.config:
dir: 'assets/img'
Now image is rendered normally using it this way:
<NuxtImg src="banners/front-page-banner.png" alt="Banner" />
But only on local development server, after building and deploying it image is not rendered and same error appears in JS console.
About this issue
- Original URL
- State: open
- Created 9 months ago
- Reactions: 8
- Comments: 41
How is it that everything always suck when its build in javascript
I’m having the same issue now. I reverted back to nuxt and modules to the last working version, but still not working. I even tried cleaning the node_modules, .nuxt, .output folders and yarn.lock, then running npx nuxi cleanup but still no change.
In developer console I see that the image is pointing to “http://localhost:3000/_ipx/_/icon.png” Using the default public dir.
Found a workaround: Do not use Nuxt Image, use Vuetifys v-img instead.
same issue in the latest version of Nuxt and Nuxt Image
@jyagamino the images appear in development server but not in production build
Same 404 error with /_ipx/ folder after “build” project. Couldn’t find the solution - have to rid all NuxtImg tags (
Using “@nuxt/image”: “^1.3.0”, “nuxt”: “^3.10.3”
I am also experiencing this issue.
following.
For most of you here, Id suggest you move your images to the root of the
publicdir and retest. That worked for me.I am having the same issue. I tried a Stackblitz: https://stackblitz.com/edit/nuxt-starter-ee1s9x
But I can’t upload images without a paid plan.
Remote images work fine.
<NuxtImg ... />flat out refuses to work with any local image.I’ve tried the images in the
publicdirectory as well asassets/images/.How to reproduce: Initialize a new Nuxt project Install and load NuxtImg module
Then, follow their documentation:
Usage <NuxtImg> outputs a native img tag directly (without any wrapper around it). Use it like you would use the
tag:
<NuxtImg src="/nuxt-icon.png" />Will result in:<img src="/nuxt-icon.png" />With default provider, you should put/nuxt-icon.pnginsidepublic/directory for Nuxt 3 make the above example work.This just doesn’t work at all.
So I’ve been looking to solve similar problems in Nuxt Content Assets, and it turns out there is a way you can do this.
Nuxt Image makes any layer’s public folder accessible via the
_ipxendpoint, so a hacky solution is to declare yourassetsfolder as a layer, and point its public folder to itself:I would prefer that Nuxt Image would allow an array for
dirbut this works in the meantime.Unfortunately, for the time being, I’ve had to use a classic image tag. But given that our site has over a hundred images, changing them manually would be really tiring. While waiting for this bug to be fixed, I proceeded as follows after research : inside composables/use-asset.ts
then i create inside components/NuxtImg.vue (override @nuxt/img NuxtImg component)
The images will not be optimized as they should be, but until the bug is fixed this may help.I am also experiencing this issue. I am not using public folder but a
mediafolder, because I do not want the source images inpublicto be copied. I runbuild&node .output/server/index.mjs. Starting this server locally, but also on a custom node setup, it will lead to a 404. As it not works out-of-the-box with a custom dir, it’s very contraintuitive. Maybe there is an easy solution @danielroe knows?So this would be the correct way after you set the
dirconfig:<NuxtImg src="banners/front-page-banner.png" alt="Banner" />Where do you deploy? According to the docs, other directories than
publicdon’t work with e.g. vercel.