Next.js Discord

Discord Forum

Image not loading on vercel prod

Unanswered
Champagne D’Argent posted this in #help-forum
Open in Discord
Champagne D’ArgentOP
Any idea why images are not loading on vercel deployment, locally they show up doing pnpm dev they also work if I locally run pnpm build and pnpm start I am confused why theey do not work on vercel prod

12 Replies

Champagne D’ArgentOP
@Jerico Aragon it is static image if I upload on another plattform and link it works. But why would I have to do that?
So it is a vercel issue?
I do not want to upload like 10 images for a one pager app on a s3 bucket to make it work...
Champagne D’ArgentOP
if I run pnpm build then pnpm start locally it works fine
just not when I deploy on vercel
Champagne D’ArgentOP
This is the code

'use client'

import { useEffect, useRef, useState } from 'react'
import { AnimatePresence, motion } from 'motion/react'
import Image from 'next/image'

const featuredPerson = {
  name: 'Sample Artist',
  role: 'DJ / Producer',
  location: 'Berlin, Germany',
  images: ['/images/sample/1.jpg', '/images/sample/2.jpg'],
  videos: ['/videos/sample/video_1.mp4', '/videos/sample/video_2.mp4'],
}

export default function FeaturedCard() {
  const [i, setI] = useState(0)
  const [isVideo, setIsVideo] = useState(true)
  const [loaded, setLoaded] = useState(false)
  const videoRef = useRef<HTMLVideoElement>(null)

  const media = [
    ...featuredPerson.videos.map((v) => ({ type: 'video' as const, src: v })),
    ...featuredPerson.images.map((i) => ({ type: 'image' as const, src: i })),
  ]

  useEffect(() => {
    const next = (i + 1) % media.length
    if (media[next].type === 'image') new window.Image().src = media[next].src
  }, [i, media])

  const item = media[i]
  const { name } = featuredPerson

  return (
    <div>
      <AnimatePresence mode='wait'>
        <motion.div
          key={i}
          initial={{ opacity: 0 }}
          animate={{ opacity: 1 }}
          exit={{ opacity: 0 }}
          transition={{ duration: 0.4 }}
          className='absolute inset-0'
        >
          {isVideo ? (
            <video
              ref={videoRef}
              src={item.src}
              autoPlay
              loop
              muted
              playsInline
              className='h-full w-full object-cover object-center'
              onLoadedData={() => setLoaded(true)}
            />
          ) : (
            <Image
              src={item.src}
              alt={`${name} - ${i}`}
              fill
              className='object-cover object-top'
              priority={!i}
              onLoad={() => setLoaded(true)}
            />
          )}
        </motion.div>
      </AnimatePresence>
    </div>
  )
}
@Champagne D’Argent This is the code ts 'use client' import { useEffect, useRef, useState } from 'react' import { AnimatePresence, motion } from 'motion/react' import Image from 'next/image' const featuredPerson = { name: 'Sample Artist', role: 'DJ / Producer', location: 'Berlin, Germany', images: ['/images/sample/1.jpg', '/images/sample/2.jpg'], videos: ['/videos/sample/video_1.mp4', '/videos/sample/video_2.mp4'], } export default function FeaturedCard() { const [i, setI] = useState(0) const [isVideo, setIsVideo] = useState(true) const [loaded, setLoaded] = useState(false) const videoRef = useRef<HTMLVideoElement>(null) const media = [ ...featuredPerson.videos.map((v) => ({ type: 'video' as const, src: v })), ...featuredPerson.images.map((i) => ({ type: 'image' as const, src: i })), ] useEffect(() => { const next = (i + 1) % media.length if (media[next].type === 'image') new window.Image().src = media[next].src }, [i, media]) const item = media[i] const { name } = featuredPerson return ( <div> <AnimatePresence mode='wait'> <motion.div key={i} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.4 }} className='absolute inset-0' > {isVideo ? ( <video ref={videoRef} src={item.src} autoPlay loop muted playsInline className='h-full w-full object-cover object-center' onLoadedData={() => setLoaded(true)} /> ) : ( <Image src={item.src} alt={`${name} - ${i}`} fill className='object-cover object-top' priority={!i} onLoad={() => setLoaded(true)} /> )} </motion.div> </AnimatePresence> </div> ) }
Let me know your vercel domain