withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.6k stars 2.47k forks source link

MDX cannot find relative image path without leading `./` #10641

Closed tisonkun closed 6 months ago

tisonkun commented 7 months ago

Astro Info

Astro                    v4.5.12
Node                     v21.6.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/sitemap
                         @astrojs/mdx

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

No response

Describe the Bug

13:05:42 [ERROR] Cannot find module 'banner.png' imported from '/Users/tison/Brittani/nightsky-blog/src/content/posts/greptimedb-community-report/index.mdx'
  Stack trace:
    at /Users/tison/Brittani/nightsky-blog/src/content/posts/greptimedb-community-report/index.mdx?astroPropagatedAssets
    [...] See full stack trace in the browser, or rerun with --verbose.
![GitHub Banner](./banner.png) works
![GitHub Banner](banner.png) failed

What's the expected result?

Both compiled

Link to Minimal Reproducible Example

https://github.com/tisonkun/repro-astro-gldfcz

Participation

OliverSpeir commented 7 months ago

Thanks for bringing this up! Recently added this functionality to markdown but not mdx, definitely would like to see this work in mdx as well.

rishi-raj-jain commented 7 months ago

@OliverSpeir

Possible to a link a PR to the markdown contribution enabling this? I'm happy to try it out for mdx.

OliverSpeir commented 7 months ago

@rishi-raj-jain

The md code

The mdx code

basically just adding the ./ if the path isn’t already relative

rishi-raj-jain commented 7 months ago

Thank you for the references, I've created the PR after testing the changes locally.