-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
nohoist @mdx-js/react with Next.js: Cannot read properties of null (reading 'useContext') #2499
Comments
Workaround 1 (remove
|
Hey @karlhorky! 👋 Why are you using a non-hoisted strategy in the first place? Duplicate copies of |
|
Thanks for the tips so far! I'm using
Indeed, I would love to switch off it. This large monorepo is one of our last projects using it. For now, it's just working around the problems :)
Ah, Next.js App Router does support It's just crashing currently because we're recursively rendering |
It's indeed probably caused by duplicate I'll see if I can find one more workaround and then we can close it as "working as intended". |
Could you just pass the |
Oh yeah, actually if either of you would know a simpler way of achieving recursive rendering of MDX files ( Currently the only one we've seen working is For an example of a "simpler" approach, I would ideally like to an approach like this (similar to the import { evaluate, type EvaluateOptions } from '@mdx-js/mdx'
import * as runtime from 'react/jsx-runtime'
import remarkGfm from 'remark-gfm';
export async function MDX(props: MDXProps) {
const { source, ...rest } = props
const { default: MDXContent } = await evaluate(source, {
useMDXComponents: () => ({ ... }),
remarkPlugins: [remarkGfm],
rehypePlugins: [],
...rest,
...(runtime as Pick<EvaluateOptions, 'Fragment' | 'jsx' | 'jsxs'>),
})
return <MDXContent />
} But it has problems with importing the child
|
Workaround 2 (add
|
Since it appears that duplicate copies of the Anyone else running into this |
Initial checklist
Affected packages and versions
@mdx-js/[email protected], [email protected], react@^18, Yarn v1.22.22
Link to runnable example
No response
Steps to reproduce
package.json
using Yarn v1 Workspaces and configuringnohoist
as belowpackages/x
and usecreate-next-app
as below@mdx-js/react
inpackages/x/package.json
(no usage necessary in Next.js app files)yarn workspace x build
and observeCannot read properties of null (reading 'useContext')
error 💥Reproduction repository: https://github.com/karlhorky/repro-mdx-react-next-js-nohoist-cannot-read-usecontext-property
Reproduction commands logs:
Expected behavior
Adding of
@mdx-js/react
package withnohoist
config should not cause Next.js build to fail withCannot read properties of null (reading 'useContext')
errorActual behavior
Adding of
@mdx-js/react
package withnohoist
config causes Next.js build to fail withCannot read properties of null (reading 'useContext')
errorRuntime
Node v20
Package manager
yarn v1
OS
macOS
Build and bundle tools
Next.js
The text was updated successfully, but these errors were encountered: