Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error: 'MDXRemote' cannot be used as a JSX component. #478

Open
robynico opened this issue Oct 11, 2024 · 0 comments
Open

Type error: 'MDXRemote' cannot be used as a JSX component. #478

robynico opened this issue Oct 11, 2024 · 0 comments

Comments

@robynico
Copy link

Describe the bug

Describe the bug

Failed to build an app next with the command : npm run build

the package.json

{
	"name": "next-app-template",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"dev": "next dev",
		"build": "next build",
		"start": "next start",
		"lint": "eslint . --ext .ts,.tsx -c .eslintrc.json --fix"
	},
	"dependencies": {
		"@nextui-org/avatar": "^2.0.33",
		"@react-aria/ssr": "3.9.4",
		"@react-aria/visually-hidden": "3.8.12",
		"clsx": "2.1.1",
		"date-fns": "^4.1.0",
		"framer-motion": "~11.1.1",
		"gray-matter": "^4.0.3",
		"intl-messageformat": "^10.5.0",
		"next": "14.2.4",
		"next-mdx-remote": "^5.0.0",
		"next-themes": "^0.2.1",
		"react": "18.3.1",
		"react-dom": "18.3.1",
		"react-syntax-highlighter": "^15.5.0"
	}
}

the page.tsx

import { MDXRemote } from "next-mdx-remote/rsc";

import { getAllPostIds, getPost } from "@/lib/post";

const components = {
  h2: ({ children }: { children: any }) => {
    const anchor = `${children.replace(/ /g, "-").toLowerCase()}`;

    return (
      <h2 data-section id={anchor}>
        {children}
      </h2>
    );
  }
};

export default async function BlogPage({
  params,
}: {
  params: { slug: string };
}) {
  const post = getPost(params.slug);

  return (
    <div className="max-h-fit">
              <MDXRemote components={components} source={post.content} />
    </div>
  );
}

export async function generateStaticParams() {
  const postIds = await getAllPostIds();

  return postIds;
}

the error at build

./app/blog/[slug]/page.tsx:125:16
Type error: 'MDXRemote' cannot be used as a JSX component.
  Its return type 'Promise<ReactElement<any, string | JSXElementConstructor<any>>>' is not a valid JSX element.
    Type 'Promise<ReactElement<any, string | JSXElementConstructor<any>>>' is missing the following properties from type 'ReactElement<any, any>': type, props, key

There is no problem with the nom run dev
thx

Reproduction

you can try on you self side

next-mdx-remote version

v5.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant