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

How to import local images? #4

Open
graup opened this issue Oct 13, 2024 · 1 comment
Open

How to import local images? #4

graup opened this issue Oct 13, 2024 · 1 comment

Comments

@graup
Copy link

graup commented Oct 13, 2024

Hi! First of all, thanks for this effort. This bring me one step closer to a nice and simple setup. What I really want is a single [slug]/page.tsx and articles as mdx files that can load local images (like ![alt text](./image.jpg)). I don't want to move images to the public folder, that seems like an ugly, not portable hack.

Does anyone know how to do that? I tried this (using MDXRemote from next-mdx-remote-client/rsc) but it gives me import errors.

// article.mdx
import imgUrl from "./image.jpg";

<img src={imgUrl} />

Error: Unknown file extension ".jpg" for /path/to/image.jpg

I tried tinkering with the nextjs webpack config but it doesn't seem to do anything (also Nextjs already can load images like this out of the box.) It seems the MDX evaluation doesn't go through webpack?

(If this would work, we could automatically turn ![alt text](./image.jpg) into that code using rehype-mdx-import-media.)

@graup graup changed the title Usage with rehype-mdx-import-media? How to import local images? (Maybe with rehype-mdx-import-media?) Oct 13, 2024
@graup graup changed the title How to import local images? (Maybe with rehype-mdx-import-media?) How to import local images? Oct 14, 2024
@talatkuyuk
Copy link
Contributor

Do you use pages router or app router in nextjs? Import doesn't work in pages router in mdx files.

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

2 participants