contentlayerdev / contentlayer

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://www.contentlayer.dev
MIT License
3.27k stars 200 forks source link

Error: Cannot read properties of undefined (reading 'ReactCurrentDispatcher') #660

Closed Virous77 closed 1 week ago

Virous77 commented 3 months ago
// NOTE use ESM/CommonJS compat import here until resolved: https://github.com/facebook/react/issues/11503
import React from 'react';
// NOTE use ESM/CommonJS compat import here until resolved: https://github.com/facebook/react/issues/11503
import ReactDOM from 'react-dom';
// @ts-expect-error React version workaround (This CJS workaround can be removed once Contentlayer is only targeting React 18+)
import { _jsx_runtime } from './jsx-runtime.cjs';
export const getMDXComponent = (code, globals = {}) => {
    const scope = { React, ReactDOM, _jsx_runtime, ...globals };
    const fn = new Function(...Object.keys(scope), code);
    return fn(...Object.values(scope)).default;
};
export const useMDXComponent = (code, globals = {}) => {
    return React.useMemo(() => getMDXComponent(code, globals), [code, globals]);
};
//# sourceMappingURL=useMDXComponent.js.map

This code is breaking when we are updating NEXT to version 15 and React to version 19. You can see the error in details below.

Image 06-06-24 at 12 13 AM

RhysSullivan commented 3 months ago

@Virous77 did you find a fix? I'm looking into patch packaging it

Virous77 commented 3 months ago

@RhysSullivan no not able to fix from my side yet.

RhysSullivan commented 2 months ago

@Virous77 couldn't find a fix I just removed content layer

Virous77 commented 2 months ago

@RhysSullivan which other package you choose and my only concern are they support remark, rehype?

nyxb commented 2 months ago

Which react do you use? the error says that the react version is not compatible. So version 0.3.4 runs with all react 18 versions.

Virous77 commented 2 months ago

@nyxb I upgraded to React RC and Next RC so i got that error. with next@14.2.3 and React@18.3.1 working well.

nyxb commented 2 months ago

@nyxb I upgraded to React RC and Next RC so i got that error. with next@14.2.3 and React@18.3.1 working well.

yeah thats what i mean

laem commented 2 months ago

Same error here with next 15 RC / React 19.

nyxb commented 2 months ago

Same error here with next 15 RC / React 19.

yeah u need to downgrade its not updated for react 19 its RC not finally

stale[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.