rehype-pretty / rehype-pretty-code

Beautiful code blocks for Markdown or MDX.
https://rehype-pretty.pages.dev
MIT License
1.01k stars 63 forks source link

Getting TS error Transformer<Root, Root>' is not assignable to type 'Plugin<any[], any, any>'. #145

Closed khanakia closed 8 months ago

khanakia commented 8 months ago

I am getting the below error however the code works fine when I compile

import { MDXRemote } from 'next-mdx-remote/rsc';
import rehypePrettyCode from 'rehype-pretty-code';

export default async function Page({ params }: any) {
  return (
    <MDXRemote
    source={`test`}
    options={{
      mdxOptions: {
        rehypePlugins: [rehypePrettyCode],
      },
    }}
  />
  );
}

Screenshot 2023-12-23 at 10 36 19 PM

o-az commented 8 months ago

This type error is because next-mdx-remote uses an old version of vfile.

The main issue in your example is:

Type 'VFileMessage' is missing the following properties from type 'VFileMessage': ancestors

vfile v6 has those properties whereas v5.3 which next-mdx-remote uses doesn't. So the issue is next-mdx-remote is using an older version of vfile dependency:

https://github.com/hashicorp/next-mdx-remote/blob/main/package.json#L17

rehype-pretty-code uses the latest version of unified which has vfile ^6 as a dependency:

https://github.com/unifiedjs/unified/blob/b69689bba52a918d87aa62f295ccffa8d9aa8ef8/package.json#L54

cc @atomiks

atomiks commented 8 months ago

Seems that next-mdx-remote should update to latest unified/vfile dependencies. For now, you can ignore the type error since runtime works fine.