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

TypeError: React.Component is not a constructor #40

Open
niklaswallerstedt opened this issue Sep 23, 2024 · 4 comments
Open

TypeError: React.Component is not a constructor #40

niklaswallerstedt opened this issue Sep 23, 2024 · 4 comments

Comments

@niklaswallerstedt
Copy link

Hey @timlrx. First off, thanks a lot for maintaining this fork. After upgrading past 0.5.0 I'm starting to get these errors

⨯ TypeError: React.Component is not a constructor
    at eval (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:13953:23)
    at eval (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:29862:5)
    at (rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js ([project_root]/packages/web/.next/server/vendor-chunks/[email protected][email protected]:20:1)
    at __webpack_require__ ([project_root]/packages/web/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/index.js:32:20)
    at (rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/index.js ([project_root]/packages/web/.next/server/vendor-chunks/[email protected][email protected]:30:1)
    at __webpack_require__ ([project_root]/packages/web/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/mdx-bundler/dist/client.js:10:40)
    at (rsc)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/mdx-bundler/dist/client.js ([project_root]/packages/web/.next/server/vendor-chunks/[email protected][email protected]:30:1)
    at __webpack_require__ ([project_root]/packages/web/.next/server/webpack-runtime.js:33:42) {
  type: 'TypeError',
  page: '/example-blog-post'
}

I've narrowed it down to my monorepo resolving react/react-dom to 18.2.0. If I override the resolved version it works again. While it may not be something on your end to fix, just reporting it in case there is something that can be fixed.

  "resolutions": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  }

I pulled out bits and pieces from another repo in a reproduction.

Node: v18.20.4

@niklaswallerstedt
Copy link
Author

Another solution is to use next-mdx-remote instead of this https://contentlayer.dev/docs/sources/files/mdx-d747e46d#app-directory

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

...

<MDXRemote source={post.body.raw} components={customComponents} />

@timlrx
Copy link
Owner

timlrx commented Sep 28, 2024

Hi @niklaswallerstedt, thanks for the example repo. I tried it out and notice that it works if installed with npm or yarn, but I am not sure what's the issue with the resolution that results in the error for pnpm.

@niklaswallerstedt
Copy link
Author

I haven't tested with npm or yarn yet but I'll give it a go.

@niklaswallerstedt
Copy link
Author

Just to clarify this started from v0.5.0 and if you downgrade contentlayer2 it should still work. At least in my project going to verify in the repro as well

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

2 participants