delucis / astro-auto-import

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

Does not work with Astro v3.3.3 and Starlight v0.11.1 #26

Closed dhruvkb closed 9 months ago

dhruvkb commented 9 months ago

With this plugin configured on Astro v2.7.0 and Starlight v.5.6, everything worked. When I updated Astro and Starlight, without any config changes, the plugin stopped working.

delucis commented 9 months ago

Could you please share a reproduction? Not sure why this might be.

dhruvkb commented 9 months ago

Sure! This is an example repo with the docs being inside the docs/ directory.

The dep_bump branch is on the latest versions of both Astro and Starlight and the imports are broken, which they aren't on main that uses slightly older versions.

dhruvkb commented 9 months ago

This is the error message that appears.

image
delucis commented 9 months ago

I think this may be Starlight-related somehow. Here’s a basic test which shows auto-imports working in MDX with latest Astro: https://stackblitz.com/edit/github-t6bbob?file=src%2Fpages%2Findex.mdx

Downgrading Starlight to v0.10 also seems to make auto-imports work again, so will need to investigate what changed recently that could break this.

delucis commented 9 months ago

Ah interesting, just tried something and I think I found a fix — will make a PR shortly.

delucis commented 9 months ago

Sure! This is an example repo with the docs being inside the docs/ directory.

Is there some kind of set-up step needed? I get errors about importing @/examples/hero/hero.mdx and that file seems to be missing from the repo.


As a quick fix for the original issue: moving autoImport() after starlight() in your integrations array in astro.config.mjs seems to fix things, although I’m not sure yet why. It’s quite confusing because usually, MDX needs to come AFTER auto-imports. We did change how Starlight enables MDX in v0.11, but I wouldn’t expect it to have this impact.

dhruvkb commented 9 months ago

Is there some kind of set-up step needed?

Sorry, my bad. This has a pretty complex setup process. I'll try to prepare a minimal reproducible example.

moving autoImport() after starlight() in your integrations array in astro.config.mjs seems to fix things

Yes, that worked perfectly. I have no idea why this order would've changed. I couldn't find any reference to import-order in the Astro changelogs. If more people experience this, it might be worth documenting the new order somewhere.

delucis commented 9 months ago

I couldn't find any reference to import-order in the Astro changelogs.

I think this was caused by a Starlight change — specifically https://github.com/withastro/starlight/commit/372ec96d31d0c1a9aa8bc1605de2b424bf9bd5af (https://github.com/withastro/starlight/pull/796) — but don’t understand yet why. In regular Astro projects, the guidance in the astro-auto-import docs continue to work, but it’s a bit of a mystery to me why that’s not the case for Starlight projects.

dhruvkb commented 9 months ago

Feel free to close this issue if you think there's nothing actionable here. And thanks for the solution, I wasn't able to update and use the newest features in Starlight till this was resolved.

delucis commented 9 months ago

Thanks. Yes, will close this as the issue is not something we can solve in this repo. Will keep investigating to understand why it's an issue with Starlight.