#Images not loading when i host the web in Vercel
1 messages · Page 1 of 1 (latest)
It sounds like you might be encountering an issue with the configuration of your next/image component when deploying to Vercel. Based on the knowledge sources, here are a few steps you can take to troubleshoot and potentially resolve the issue:
-
Check
next.config.jsConfiguration:
Ensure that the hostname for the images is correctly configured in yournext.config.jsfile. This is a common issue that can prevent images from loading correctly when deployed.Example configuration:
// next.config.js module.exports = { images: { domains: ['example.com'], // Add your image host domain here }, }If the hostname is not configured, you might see an error like:
Error: Invalid src prop <url> on `next/image`, hostname <hostname> is not configured under images in your `next.config.js`Source: GitHub Issue #62167 (https://github.com/vercel/next.js/issues/62167)
-
Image Optimization:
Vercel automatically optimizes images on demand when you deploy your Next.js application. Ensure that your images are being served from the Vercel Edge Network, which can help with performance and loading issues.Source: Image Optimization Quickstart (https://vercel.com/docs/image-optimization/quickstart)
-
Use the Next.js Image Component:
Make sure you are using thenext/imagecomponent correctly. Here is an example of how to use it for a background image:import Image from 'next/image' import ViewSource from '../components/view-source' import { bgWrap, bgText } from '../styles.module.css'
const Background = () => (
<div>
<ViewSource pathname="pages/background.js" />
<div className={bgWrap}>
<Image
alt="Mountains"
src="/mountains.jpg"
layout="fill"
objectFit="cover"
quality={100}
/>
</div>
<p className={bgText}>
Image Component
<br />
as a Background
</p>
</div>
)
export default Background
Source: **Best Practices for Hosting Videos on Vercel** (<https://vercel.com/guides/best-practices-for-hosting-videos-on-vercel-nextjs-mp4-gif#what-about-images>)
4. **Check Image Formats and Metadata**:
Ensure that the image formats you are using are appropriate and that there are no issues with metadata that might be causing the images to fail to load.
Source: **Images on the Web** (<https://vercel.com/guides/images-on-the-web#conclusion>)
By following these steps, you should be able to identify and resolve the issue with images not loading when your project is hosted on Vercel. If the problem persists, you might want to check the Vercel documentation or open an issue on the Next.js GitHub repository for further assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@dawn salmon kapa.ai is still learning and improving, please let us know how it did by reacting below
@mellow galleon i have the same component for 3 images, 2 of them are loading well, why the thrid not? <Image
src={/productos/packs/${img}.png}
width={200}
height={200}
alt={foto silla ${nombre}}
className="h-full w-auto"
/>