withastro / docs

Astro documentation
https://docs.astro.build/
MIT License
1.34k stars 1.51k forks source link

⚠️ Issue @astro/mdx keeps crushing due to rehype dependency #8399

Closed MwirabuaTimothy closed 6 months ago

MwirabuaTimothy commented 6 months ago

Every time I install @astro/mdx using the manual process I get the error below:

3:48:26 PM [vite] Error when evaluating SSR module site/astro.config.ts: failed to import "@astrojs/mdx"
|- Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'site/node_modules/astro/dist/jsx/rehype.js' imported from site/node_modules/@astrojs/mdx/dist/vite-plugin-mdx.js
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:326:11)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
[astro] Unable to load your Astro config

I have to use automatic way of npx astro add mdx plus I have to have rehype installed as a dev dependency otherwise I get the same error above.

MwirabuaTimothy commented 6 months ago

Also whenever I add other remark plugins, @astro/mdx crushes with the same error. So I have to first uninstall @astro/mdx and remove it from the astro.config.ts, complete adding and testing the other remark plugin, then come back and install @astro/mdx using the npx astro add mdx

TheOtterlord commented 6 months ago

I'm not able to replicate this. Are you able to share your repo, or a minimal reproduction? I'll close this issue as it doesn't seem this isn't related to the docs. Feel free to continue discussing with me here, or join our Discord to share in our support channels.

bartlomiejzuber commented 6 months ago

Hey, we had same issue with our project. After investigation we've found out that the problem was on our side, we've added a mdx integration with: pnpm astro add mdx

But we also had a line in .npmrc with: strict-peer-dependencies=false

Which in result caused ignoring peerDependencies property on package.json, that in result pulled latest @astrojs/mdx which didn't work because we had an astro version set to 4.5.1.

If you have same issue either upgrade your astro to ^4.8.0 or downgrade @astrojs/mdx.