Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue components cannot reference images in public folder #9328

Closed
1 task
ffxsam opened this issue Dec 5, 2023 · 4 comments · Fixed by #10419
Closed
1 task

Vue components cannot reference images in public folder #9328

ffxsam opened this issue Dec 5, 2023 · 4 comments · Fixed by #10419
Assignees
Labels
- P2: has workaround Bug, but has workaround (priority) ecosystem: upstream Upstream package has issue help wanted Please help with this issue!

Comments

@ffxsam
Copy link
Contributor

ffxsam commented Dec 5, 2023

Astro Info

Astro                    v4.0.1
Node                     v18.16.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/vue

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

References images in /public seems to be broken in Vue components:

<template>
  <div>
    <img src="/favicon.svg" />
  </div>
</template>

What's the expected result?

I'd expect to see an image displayed. This works in Astro 2.x, and it works in an .astro component in 4.x.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-njmj9o

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 5, 2023
@Princesseuh
Copy link
Member

There seems to be a bug in the Vue Vite plugin causing the related setting to not work properly.

A bit of a clunky workaround in the meantime:

import { defineConfig } from "astro/config";
import vue from "@astrojs/vue";

// https://astro.build/config
export default defineConfig({
  integrations: [
    vue({
      template: {
        transformAssetUrls: {
          includeAbsolute: false,
        },
      },
    }),
  ],
});

You might get a type error with this, but it should work, at least!

@Princesseuh Princesseuh added - P2: has workaround Bug, but has workaround (priority) pkg: vue Related to Vue (scope) labels Dec 6, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Dec 6, 2023
@yoyo837
Copy link
Contributor

yoyo837 commented Dec 6, 2023

Same here.

When the assets/img/yhfootball/tips.png image exists in the public folder and is referenced using <img src="/assets/img/yhfootball/tips.png" />, it reports this error:

[ImageNotFound] Could not load vite:asset:public/assets/img/yhfootball/tips.png (imported by src/pages/yhfootball/index.vue): Could not find requested image `vite:asset:public/assets/img/yhfootball/tips.png`. Does it exist?
  Hint:
    This is often caused by a typo in the image path. Please make sure the file exists, and is spelled correctly.
  Error reference:
    https://docs.astro.build/en/reference/errors/image-not-found/

@Princesseuh Princesseuh added ecosystem: upstream Upstream package has issue and removed pkg: vue Related to Vue (scope) labels Feb 6, 2024
@marsidev
Copy link

Another workaround that worked for me was change <img src="/path/to/img.webp" /> to <img :src="'/path/to/img.webp'" />

@hepayoo
Copy link

hepayoo commented Sep 8, 2024

Another workaround that worked for me was change <img src="/path/to/img.webp" /> to <img :src="'/path/to/img.webp'" />

i had the same prob but this worked for me thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) ecosystem: upstream Upstream package has issue help wanted Please help with this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants