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

🐛 BUG: Image imports work in development but not in production #772

Closed
matiaskorhonen opened this issue Jul 20, 2021 · 7 comments
Closed

Comments

@matiaskorhonen
Copy link

matiaskorhonen commented Jul 20, 2021

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

Image imports work in development but not in production.

I have a component, Header (src/components/Header.astro) that imports an image from within src/:

---
import logo from "./logo.svg";
---
<header>
    <div>
        <img width="1280" height="300" src="{logo}" alt="Logo">
    </div>
</header>

This seems to work just fine in development mode but astro build doesn't copy the asset to the dist/ folder.

If buildOptions.site is set, the image doesn't get copied but if it's commented out it does.

Steps to Reproduce

  1. npm init astro using template ‘Starter Kit (Generic)’ with Svelte
  2. Add a component that imports an image from within src/
  3. Set buildOptions.site to any hostname
  4. Build the site
  5. Check the dist/ folder
  6. The image isn't present!

Link to Minimal Reproducible Example (Optional)

https://github.com/matiaskorhonen/astro-image-bug

@matiaskorhonen matiaskorhonen changed the title 🐛 BUG: 🐛 BUG: Image imports work in development but not in production. Jul 20, 2021
@matiaskorhonen matiaskorhonen changed the title 🐛 BUG: Image imports work in development but not in production. 🐛 BUG: Image imports work in development but not in production Jul 20, 2021
@woodbrettm
Copy link

woodbrettm commented Jul 24, 2021

I'm finding the same issue as well, even with a manual set-up.

I have certain assets that I want to run through the build, for example SVGs that I want optimized using SVGO. Those are put in an src/assets folder.

When running the build command, it looks like the markup is correctly referencing /_astro/src/assets..., however the assets aren't actually copied over.

The only way I'm finding for the assets to be copied is to put them in the public folder. However then I can't put them through the build process. And it seems they're not always properly loaded in the dev server when sourced from the public folder

@jasikpark
Copy link
Contributor

This definitely feels connected to #492 to a certain degree - since if we had a set way to consumed and output compiled assets this might work easier.. though I imagine that an image included in /src should be copied over to the dist/ if it is referenced without being transformed?

@woodbrettm
Copy link

I think by default that would make sense, and then layering any plugins on top of that for transformations.

@matthewp
Copy link
Contributor

I think this is likely something we are getting for free via Snowpack but not handling during the build.

@matthewp matthewp added the build label Jul 27, 2021
@matiaskorhonen
Copy link
Author

FWIW, the docs say that this should work: https://docs.astro.build/guides/imports#other-assets

@stephanbogner
Copy link
Contributor

FWIW: Same bug just happened to me too (Astro v0.20.12 via NPM, Mac)
If I remove "site" from buildOptions, it works, otherwise it doesn't.
And obviously it would be amazing if this were fixed 😅

@FredKSchott
Copy link
Member

Thanks for the report! We believe that this has been fixed in astro v0.21, going out today. Let us know if you can still reproduce the issue after updating to v0.21 and we'll be happy to take a look.

xstevenyung pushed a commit to xstevenyung/astro that referenced this issue Oct 17, 2023
* updating astro-related deps

* updating fontsource variable imports

* Updating to the latest MDIO 0.6 font

* chore: lint updates

* chore: a few type fixes for lint warnings

* linters are the worst

* TEMP: rolling back @astrojs/netlify

* latest Tailwind, less specific pnpm version

* ah right, language tools expects the Props type at the top!  Will follow-up separately

* well that's fun, the pnpm@^8.0.0 syntax is valid but fails in CI builds

* lint fixes for the latest Tailwind release

* just peg to pnpm@8.6.12

---------

Co-authored-by: Tony Sullivan <tony.f.sullivan@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants