Next.js Discord

Discord Forum

Typescript error using next-mdx-remote

Answered
Brian GF posted this in #help-forum
Open in Discord
I am following the instructions for using Remote MDX at https://nextjs.org/docs/app/building-your-application/configuring/mdx#remote-mdx .

When I paste this code into VSCode as suggested by the docs
import { MDXRemote } from "next-mdx-remote/rsc";

export default async function RemoteMdxPage() {
// MDX text - can be from a local file, database, CMS, fetch, anywhere...
const res = await fetch("https://...");
const markdown = await res.text();
return <MDXRemote source={markdown} />;
}

I am getting the following typescript error
[{
"resource": "/c:/Users/brian/Code/Active/nptechadvisor/app/my-mdx-page-remote/page.tsx",
"owner": "typescript",
"code": "2786",
"severity": 8,
"message": "'MDXRemote' cannot be used as a JSX component.\n Its return type 'Promise<ReactElement<any, string | JSXElementConstructor<any>>>' is not a valid JSX element.\n Type 'Promise<ReactElement<any, string | JSXElementConstructor<any>>>' is missing the following properties from type 'ReactElement<any, any>': type, props, key",
"source": "ts",
"startLineNumber": 7,
"startColumn": 11,
"endLineNumber": 7,
"endColumn": 20
}].

Any idea why?

7 Replies

try npm install @types/react@latest --save-dev
I am already at the latest, but it does give me the following warning PS C:\Users\brian\Code\Active\nptechadvisor> pnpm install @types/react@latest --save-dev
 WARN  2 deprecated subdependencies found: core-js@2.6.12, querystring@0.2.0
Already up to date
Progress: resolved 1315, reused 1306, downloaded 0, added 0, done
Done in 8.5s
My full package json (and the rest of the rep) is at https://github.com/briangflett/nptechadvisor/blob/master/package.json
Answer
I have cloned your repo and tested, it works
Many thanks for looking at this Ray. I think part of the problem was I had my global modules installed with npm and my project modules intsalled with pnpm. I have reverted back to npm for everything and followed the advice above and everything is working. Many Thanks!!