RafidMuhymin / astro-imagetools

Image Optimization tools for the Astro JS framework
astro-imagetools-docs.vercel.app
MIT License
401 stars 45 forks source link

<img/> src undefined when specifying formats #128

Open stephanbogner opened 2 years ago

stephanbogner commented 2 years ago

Issue

src="undefined" when using the format option

How to reproduce:

  1. Install Astro with "Just the basics" using npm create astro@latest (in my case version 1.4.7")
  2. Install ImageTools using npm install astro-imagetools (in my case version 0.6.11)
  3. Replace content of astro.config.mjs with content from docs
import { astroImageTools } from "astro-imagetools";

export default {
  integrations: [astroImageTools],
};
  1. Add an image to /public, e.g. this one
  2. Edit /pages/index.astro:
---
import { Img } from "astro-imagetools/components";
import Layout from '../layouts/Layout.astro';
---

<Layout title="Welcome to Astro.">
    <Img src="/the-nix-company-ljvm17bH-e0-unsplash.jpeg" alt="A random image" />
</Layout>
  1. Create astro-imagetools.config.mjs and set:
import { defineConfig } from "astro-imagetools/config";

export default defineConfig({
  format: ["webp", "jpg"]
});

Result

Generated img tag:

<img
    src="undefined"
    alt="A random image"
    srcset="/assets/the-nix-company-ljvm17bH-e0-unsplash@320w.719a2856.webp 320w, /assets/the-nix-company-ljvm17bH-e0-unsplash@840w.74347f00.webp 840w, /assets/the-nix-company-ljvm17bH-e0-unsplash@1286w.a64e271f.webp 1286w, /assets/the-nix-company-ljvm17bH-e0-unsplash@1657w.9c355a1e.webp 1657w, /assets/the-nix-company-ljvm17bH-e0-unsplash@1954w.c1b93de0.webp 1954w, /assets/the-nix-company-ljvm17bH-e0-unsplash@2177w.54e4f1e1.webp 2177w, /assets/the-nix-company-ljvm17bH-e0-unsplash@2326w.fc352684.webp 2326w, /assets/the-nix-company-ljvm17bH-e0-unsplash@2400w.ee938d08.webp 2400w"
    sizes="(min-width: 2400px) 2400px, 100vw"
    width="2400"
    height="3595"
    loading="lazy"
    decoding="async"
    class="astro-imagetools-img astro-imagetools-img-7C93DA38"
    style="display: inline-block; overflow: hidden; vertical-align: middle; ; max-width: 100%; height: auto;"
    onload="">

Expected Result:

The same as above but with a src.

Test with empty config import { defineConfig } from "astro-imagetools/config"; export default defineConfig({ });
Generated image tag with correct src: A random image
laurieherault commented 1 year ago

I have the same problem.

sethzindler commented 1 year ago

Having the same issue.

mark-mybaggage commented 8 months ago

Same issue