#<Image /> component only work in Production, not in Dev

3 messages · Page 1 of 1 (latest)

pure notch
#

I'm having a problem using the <Image /> component together with the Collections.

Context

  • macOS Ventura 13.6.1
  • pnpm as package manager
  • Chrome as the browser
  • It works fine hosted on Vercel
  • It does not work when I run pnpm run dev

What's happening

The images only show in Production at the live site URL. They do not work in development.

What I did

I defined the collection as so:

const authors = defineCollection({
  type: 'content',
  schema: ({ image }) =>
    z.object({
      // other props…
      image: image()
    })
})

The images are in src/content/authors/image.jpeg, the same folder as the markdown files and used like this:

---
image: './image.jpeg'
---

I'm using it in the Component.astro files like this:

---
import { Image } from 'astro:assets'
import { getCollection } from 'astro:content'

const authors = await getCollection('authors')
---

<ul>
  {authors.map((author) => (
    <li>
      {author.data.image && (
        <Image
          width={200}
          height={200}
          src={author.data.image}
          alt={author.data.fullName} />
      )}
    </li>
  ))}
</ul>
dense minnowBOT
#

Hi @pure notch. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems that there have been several issues reported on GitHub regarding the Astro <Image /> component not working as expected in development mode. However, the specific issue you're encountering with Collections and the <Image /> component in development mode is not directly addressed in the extracts.

Here are some of the related issues that have been reported:

  1. Asset optimization (Image tag) doesn't work in dev server, but works after build (https://github.com/withastro/astro/issues/8486)
  2. Astro Image component doesn't work in production in Vercel (https://github.com/withastro/astro/issues/4536)
  3. img MDX component override is not used in Astro collections (https://github.com/withastro/astro/issues/7223)
  4. Astro Image/img works locally but not on Vercel - build creates wrong path for img src (https://github.com/withastro/astro/issues/7536)
  5. Astro Image component @astrojs/image does not work on Netlify using SSR (https://github.com/withastro/astro/issues/8157)
  6. Astro Image component does not work on Netlify using SSR (https://github.com/withastro/astro/issues/4794)

While these issues might not be exactly the same as yours, they indicate that there might be some inconsistencies or bugs with the <Image /> component in different environments or use cases.

I recommend checking these issues and their solutions or workarounds to see if they can help you. If not, consider opening a new issue on the Astro GitHub repository detailing your problem. Make sure to provide all the necessary details, including your Astro version, operating system, package manager, and a minimal reproducible example if possible.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: