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
Inconsistent behaviour between build and dev with /src/assets
#10634
Comments
After further investigation, the issue seems to be that the images are actually displaying in I should be using the Therefore, the expected result should be that |
/src/assets
/src/assets
This is because Vite serves the filesystem in dev, nothing to do with assets or images in particular. I've always found this quite weird personally, but I assume that Vite uses this for specific reasons |
Vite supports root-relative paths as it's advertised as a glorified filesystem server that serves files from your project root. There's a few explorations in the past to make this more strict, e.g. only allowing behind I think we can support this in Astro if we want to since we call astro/packages/astro/src/vite-plugin-markdown/index.ts Lines 80 to 81 in f226cb6
And it can resolve root-relative paths and public paths, and do some additional checks there. But I'm also fine if we want a blanket "starts with / is never handled": astro/packages/markdown/remark/src/remark-collect-images.ts Lines 28 to 31 in f226cb6
|
I don't think we should try and support this, otherwise people will expect it in other places as well. |
Yeah, I agree with Matthew here. I would keep the behaviour as simple as possible and clarify the user expectations. |
After discussing this we think this might be reasonable to support and not be too difficult to implement. |
in the meantime is there any way to have the images display normally on the build? |
You can use relative paths, or use aliases like |
@bluwy those didn't work, relative paths get passed as a string of text for some reason when used in .md and importing through assets directly doesn't work for build. So this is how i kinda fixed this, i had to add those images on public/images, have to update astro(if not running latest) and then import them. |
Could you share the code for this? Relative links and aliases were working in my original project (and the example code - relative links are used as an example of how it should be working) |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
All
Describe the Bug
I have an
md
file referencing an image/gif:If I run
astro dev
, it displays the image fine, however runningastro build
, the image does not show on the website (in place it just has the alt text)From looking at the files, it does not transfer/build the images into the
dist
directory.If I change the link to a relative one e.g.
../../assets/image.gif
it works absolutely fineWhat's the expected result?
Consistency between
astro dev
andastro build
when using/src/assets
.EDIT: please see comment below, but in summary, the image should not be displayed in both instances
Link to Minimal Reproducible Example
https://github.com/WilfSilver/astro-asset-link-issue
Participation
The text was updated successfully, but these errors were encountered: