withastro / docs

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

Typings cannot be resolved for `markdown.rehypePlugins` in `astro.config.ts` file #4779

Closed idlist closed 11 months ago

idlist commented 1 year ago

Astro Info

Astro                    v3.0.10
Node                     v20.5.1
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/vue
                         @astrojs/mdx
                         @astrojs/sitemap

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

No response

Describe the Bug

I'm trying to follow the Add icons to external links recipe, and I ran into this problem:

image

The error says:

image

a workaround would be (or actually it might be the only practical solution for now):

image

What's the expected result?

No errors are reported.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-pxea2u?file=astro.config.ts&on=stackblitz

Participation

idlist commented 1 year ago

My current thought is that as the type RehypePlugin is actually conflicting with the type Plugin unified provided (if you denote a plugin using unified's Plugin, then you have to use as unknown as RehypePlugin for it to work), and most of the official or community plugins are written in JavaScript (some with d.ts annotations), for now it might be better to just update the docs about setting up TypeScript to mention that you might need to use as RehypePlugin as a workaround... 🤔

natemoo-re commented 1 year ago

I'm going to move this over to the docs repo since it's a DX issue with a package they recommend!

kevinzunigacuellar commented 1 year ago

It looks like the file might be missing a title. Additionally, there seems to be a conflict between the file name and the code block extension. The text references a .mjs document, but the code block is marked as TypeScript.

mingjunlu commented 1 year ago

Haven't figured out the reason yet, but manually installing @types/hast (one of rehype-external-links' dependencies) seems to resolve the error 🤔

npm install --save-dev @types/hast@^3.0.0
idlist commented 11 months ago

I don't know why but updating to newer Astro version (still in v3) fixes this issue. And it seems like Astro v4 does not have this issue, so I'm closing this issue for now.


Edit: I just found that it might be because that I installed @types/hast (though for my case it's because I needed it for using hast related utilities) that I didn't have the issue anymore. If someone still have this issue and happens to see this thread, please try installing it (as said above).