hashicorp / next-mdx-remote

Load MDX content from anywhere
Mozilla Public License 2.0
2.58k stars 139 forks source link

Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'default') #369

Open theabhayprajapati opened 1 year ago

theabhayprajapati commented 1 year ago

image

SOURCE CODE.

when even i use MDXRemote component i am getting this error. please let me know how can i fix this.

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

const Test = () => <div>TEST</div>;
const components = { Test };

export default function TestPage({ source }) {
  return (
    <div className="wrapper">
      <MDXRemote {...source} components={components} />
    </div>
  );
}

export async function getStaticProps() {
  // MDX text - can be from a local file, database, anywhere
  const source = "Some **mdx** text, with a component <Test />";
  const mdxSource = await serialize(source);
  return { props: { source: mdxSource } };
}
{

  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@mdx-js/loader": "^2.3.0",
    "@mdx-js/react": "^2.3.0",
    "@next/mdx": "^13.4.3",
    "@types/mdx": "^2.0.5",
    "@types/node": "20.2.3",
    "@types/react": "18.2.6",
    "@types/react-dom": "18.2.4",
    "autoprefixer": "10.4.14",
    "eslint": "8.41.0",
    "eslint-config-next": "13.4.3",
    "next": "13.4.3",
    "next-mdx-remote": "^4.4.1",
    "postcss": "8.4.23",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "tailwindcss": "3.3.2",
    "typescript": "5.0.4"
  }
}

Built with "next": "13.4.3",

BRKalow commented 1 year ago

@theabhayprajapati Can you spin up a codesandbox or a repository with a minimal reproduction? That will make it easier for us to determine the root cause, thanks!

nneven commented 7 months ago

@theabhayprajapati did you ever get this resolved? I am experiencing the same issue

ShaikMoAbdullah commented 7 months ago

Facing the same issue.

dendrofen commented 6 months ago

The same issue with nextjs turbo

chetanpan commented 4 months ago

Anybody found solution to this?

dstaley commented 4 months ago

If anyone can provide a minimal reproduction I'd be happy to take a look.

chetanpan commented 4 months ago

@dstaley check this sandbox

Error is about hydration..can you please help?

dstaley commented 4 months ago

@chetanpan That sandbox is private. Mind making it public so I can access it?

chetanpan commented 4 months ago

@dstaley sorry, please check again...made it public...

dstaley commented 4 months ago

@chetanpan Upgrade to the latest version of Next to get better hydration errors. <hr /> can't be a child of <p>.

image

chetanpan commented 4 months ago

@dstaley

I have upgraded to latest next, also changed to very simple code.

Still getting hydration error.

dstaley commented 4 months ago

@chetanpan Can you see if the issue occurs with next-mdx-remote@0.0.0-canary-20240321205249? I don't think it does, so this might be a MDX v2 issue that was fixed in v3.

chetanpan commented 4 months ago

@dstaley, I tried with canary, same error. Page (uses compilation) hydration error seems to have something to do with MDXContent rendering. Page2 (uses MDXRemote) gives error about MDXRemote as well.

Also, I have observed that if I use <>{result.content}</> instead of <div>{result.content}</div>, it works fine! How come?

dstaley commented 4 months ago

@chetanpan I'm not seeing the same behavior in my fork of your CodeSandbox. Since this is mainly hydration issues (and not Cannot read properties of undefined) would you mind opening a new issue with a reproduction? We can take a closer look together there!

chetanpan commented 4 months ago

@dstaley I get error in your fork in chrome as well...So, I tried Firefox, alas, error is there, too

I will create new issue.