delucis / astro-auto-import

Auto-import components in Astro projects
84 stars 2 forks source link

Usage with Starlight #40

Closed marcosmartini closed 4 months ago

marcosmartini commented 4 months ago

Is it possible to use this package with Starlight? I was reading through Astro's Discord where people were recommending this but I could not make this work.

Here is a link to a basic repro: https://stackblitz.com/edit/github-rbo2vn?file=src%2Fcontent%2Fdocs%2Fguides%2Fexample.mdx

Any help is appreciated! Thanks for the great package!

marcosmartini commented 4 months ago

Sorry, just figure it out: This integration needs to come after Starlight in astro.config

Thanks again @delucis!

evadecker commented 1 week ago

Hey @delucis, question! When AutoImport is placed after Starlight, as @marcosmartini stated, everything works fine! But the package throws a warning in the console:

[auto-import] ⚠️ @astrojs/mdx initialized BEFORE astro-auto-import.
Auto imports in .mdx files won’t work!
Move the MDX integration after auto-import in your integrations array in astro.config.

Starlight initializes MDX automatically, and auto-importing seems to work fine when placed afterwards. I could add the @astrojs/mdx package and import it manually after AutoImport, but that feels odd since Starlight already handles it. What's the suggested course of action to silence the warning in the console?

delucis commented 1 week ago

Huh, good question. At least with Starlight it appears MDX needs to run before auto-import? Maybe something changed with the MDX integration? 🤔

I think you can ignore the warning as it seems to be wrong, but we’ll need to dig into why this is happening. Would you be able to open an issue to track this?

Here’s a quick StackBlitz test with latest versions of both integrations: https://stackblitz.com/edit/github-jqmc1e?file=astro.config.mjs

evadecker commented 4 days ago

Opened an issue here: https://github.com/delucis/astro-auto-import/issues/46