next.js: As of [15.2.0-canary.57] throws TypeError: Cannot read properties of undefined (reading 'stack')
Link to the code that reproduces this issue
https://github.com/talatkuyuk/next15-canary-bug-reproduction
To Reproduce
The app which I provided its link is a bug reproduction for next@15.2.0-canary.57 and still continues in next@15.2.0-canary.70 which is latest canary.
It throws the error below in only development mode, not in production.
The error occurs in the nextjs page (MDX article) related with importing a .mjs react component into MDX. I put another article page to show importing a module/function in MDX works well without problem.
TypeError: Cannot read properties of undefined (reading 'stack')
at stringify (<anonymous>)
at stringify (<anonymous>) {
digest: '3183793578'
}
Actually, there is no problem with the Next.js versions below (All, I tested). Importing a .mjs react component into MDX works well.
next@15.1.7next@15.2.0-canary.0next@15.2.0-canary.10next@15.2.0-canary.20next@15.2.0-canary.30next@15.2.0-canary.40next@15.2.0-canary.50next@15.2.0-canary.56
Step to produce the error
npm run dev–> open browser and click to articles, and see the error in development mode.
npm run build and npm run start --> open browser and click the articles, see there is NO error in production mode.
Then, install the previous canary version to test it.
npm i -S next@v15.2.0-canary.56
rm -rf .next && npm run dev
and see there is NO error in development and production modes.
Then, install the canary.57 again,
npm i -S next@v15.2.0-canary.57
rm -rf .next && npm run dev
and see the TypeError in development mode.
What is next-mdx-remote-client
The next-mdx-remote-client is a fork of next-mdx-remote, having more features like supporting import statements in MDX.
It works well with all versions of Next.js (13, 14, 15) for one year almost.
Log in the console related with the error
I put it in the end because it is long:
[Error] TypeError: Cannot read properties of undefined (reading 'stack')
resolveErrorDev
processFullStringRow
processFullBinaryRow
progress
The above error occurred in the <Unknown> component. It was handled by the <DevOverlayErrorBoundary> error boundary.
onCaughtError (error-boundary-callbacks.js:53)
logCaughtError (react-dom-client.development.js:8138)
runWithFiberInDEV (react-dom-client.development.js:1474)
(anonim işlev) (react-dom-client.development.js:8185)
callCallback (react-dom-client.development.js:4841)
commitCallbacks (react-dom-client.development.js:4861)
runWithFiberInDEV (react-dom-client.development.js:1474)
commitClassCallbacks (react-dom-client.development.js:11062)
commitLayoutEffectOnFiber (react-dom-client.development.js:12182)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12110)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12105)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12291)
recursivelyTraverseLayoutEffects (react-dom-client.development.js:13296)
commitLayoutEffectOnFiber (react-dom-client.development.js:12187)
flushLayoutEffects (react-dom-client.development.js:17269)
commitRoot (react-dom-client.development.js:17106)
commitRootWhenReady (react-dom-client.development.js:16183)
performWorkOnRoot (react-dom-client.development.js:16087)
performWorkOnRootViaSchedulerTask (react-dom-client.development.js:17995)
performWorkUntilDeadline (scheduler.development.js:36)
Current vs. Expected behavior
Expecting no error, and show the article page without problem.
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:22:00 PST 2025; root:xnu-11215.81.4~3/RELEASE_X86_64
Available memory (MB): 16384
Available CPU cores: 12
Binaries:
Node: 18.20.5
npm: 10.8.2
Yarn: 1.22.22
pnpm: 10.4.1
Relevant Packages:
next: 15.2.0-canary.57 // There is a newer canary version (15.2.0-canary.70) available, please upgrade!
eslint-config-next: 15.1.7
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
It throws the error in only development mode in local, not in production.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 36
- Comments: 32 (10 by maintainers)
Commits related to this issue
- bug: Temporary fix for issue relating to vercel/next.js#76395 & refactoring for Next 15 async params — committed to FluroAsh/nextjs-mdx-portfolio by FluroAsh 2 years ago
- bug: Temporary fix for issue relating to vercel/next.js#76395 & refactoring for Next 15 async params — committed to FluroAsh/nextjs-mdx-portfolio by FluroAsh 2 years ago
- bug: Temporary fix for issue relating to vercel/next.js#76395 & refactoring for Next 15 async params — committed to FluroAsh/nextjs-mdx-portfolio by FluroAsh 2 years ago
- ⬇️ downgrade to `next@15.2.0-canary.56` (https://github.com/vercel/next.js/issues/76395) — committed to onRuntime/onruntime-website by antoinekm 2 years ago
- ⬇️ downgrade to `next@15.2.0-canary.56` (https://github.com/vercel/next.js/issues/76395) — committed to onRuntime/onruntime-website by antoinekm 2 years ago
This workaround solved it for me:
Interesting conversation. For what it’s worth, I’m not using “next-mdx-remote-client” but "“next-mdx-remote”. Together with the upgrade to Next 15.2.0, I also upgraded “next-mdx-remote” to version 5.0.0. Since then I’m also getting in development mode these errors:
⨯ [TypeError: Cannot read properties of undefined (reading ‘stack’)] { digest: ‘890473477’
In production, these errors don’t occur.
Basically all is similar to the behaviour described above for the “next-mdx-remote-client”.
Same as the others, I’m also getting the same behavior described above with contentlayer2, on any
Nextversions above15.2.0-canary.56.Production builds run fine, only getting this error in dev.
It worked for me in the following scenario:
next-mdx-remote-client@2.1.1next@15.2.0My code was previously using:
I changed it to:
This new package works
next dev --turbopacknext buildfollowed bynext startAfter this,
next-mdx-remotecan be removed altogether andnext-mdx-remote-clientis not needed intranspilePackageseither.Hi @eps1lon, thank you for reply, and for taking your time to solve the problem.
Are you saying that the problem is not caused by a change in
15.2.0-canary.57, but that there is an inherent situation inReflect.constructregarding the import of thereactwithin?Even if such a situation is true, I’m trying to understand why the same problem did not occur in previous
nextversions. In all previous versions ofnext, there was no problem and the mdx compiled source is being able to be hydrated viaReflect.constructwhile mdx source is importing a.mjsreact component. (in app router, not pages router)If your diagnosis was correct, why does the issue NOT occur in production and the error occurs only in development environment?
Evaluation and hydration of compiled source in such a case in
next-mdx-remote-client/rscoccurs in server side. It doesn’t use dynamic importimport(). And, the importing the module/component does not occur in the client side in MDX evaluation, but in rsc environment.In
Next.js, the “Dev Overlay” is an interactive error overlay that helps developers identify and debug issues while running the app in development mode (next dev). I think the issue may be related withdev overlay. Because I see some commits aboutdev overlayinnext@15.2.0-canary.57. For example, thedev overlayis enabled by default. I see also a commit about[dev overlay] fix: call stack ...See all commits (changes) in that version. (it is so similar with TypeError: Cannot read properties of undefined (reading ‘stack’))I need to get the issue solved. May other expertises also see the issue? @ztanner @devjiwonchoi
Fixed in
next-mdx-remote-client@2.1.0.I’ve passed the
Reactmodule into the evaluated code in the new version v2.1.0 ofnext-mdx-remote-client. I made theReactis available in the imported components.Now,
next-mdx-remote-clientworks withnext@15.2.2without problem.You can have a look for more explanation here https://github.com/ipikuka/next-mdx-remote-client/issues/9#issuecomment-2707458632.
I don’t know how other libraries suffers from the issue, it may provide an inspiration for further solution.
[ update 11/03 ]
Next.js v15.2.2 has been tested, and
next-mdx-remote-clientstill works with no problem since the evaluated code has aReactinstance in which is passed internally.In my case it was
next-seotoo thank you @talatkuyuk@jpmonette that worked for me too. I’m using
next-seowhere I had a problem with the<BreadcrumbJsonLd useAppDir itemListElements={jsonLdBreadcrumbs} />component. Using this in dev would break the app, but in prod it works fine. The transpilePackages fix will do for now.Is there an update on this?
React.or* as Reactimportscanary-3-6, https://github.com/aymericzip/intlayer/issues/103#issuecomment-2711308194This is a pre-existing bug with these libraries. E.g.
React.useId()wasn’t working either. The affected library need to pass in the React module into the evaluated code instead of having the evaluated code import React which wouldn’t be affected by bundlers.Hi @AntoineKM,
next-mdx-remote-clientworks without any issues including this one. if you can provide a minimal reproduction, I can solve the issue more efficiently.If the issue is related to the onruntime-website, I noticed that it also uses
next-seo, which is affected by this issue. See the comment.I switched from next-mdx-remote to next-mdx-remote-client, and i still have the same issue 👀
Hi @talatkuyuk,
Thank you for your insights.
Regarding
cloneElement, I was limited by its compatibility with the new Lynx framework.Additionally,
return React.cloneElement(element, { value })makesvalueaccessible aselement.props.valuerather thanelement.value, which is what I intendedI agree that this is not understandable
There may be multiple reasons causing this error. However, for those who want to reproduce the issue:
I remember when Next.js upgraded from 14 to 15, I had a similar issue with Contentlayer, so I switched to next-mdx-remote. Now it’s happening again. Maybe we should move to a headless CMS or an API-based solution.
@talatkuyuk, thanks for the insightful feedback.
My solution works within a fairly specific set of constraints that might not be applicable to everyone. Specifically, I’m taking advantage of Next.js’s App Router and Server Components architecture. This allows me to perform the entire MDX evaluation on the server, which inherently avoids the client-side React versioning and bundling issues that seem to be at the root of the reported problems. The use of ‘baseUrl’ also becomes unnecessary as everything is being rendered on the server side without further processing on the client side.
Furthermore, I’m carefully managing the complexity of my MDX content. I am not using dynamic import statements within the MDX. I mostly rely on passing pre-imported, server-side React components to the <MDXContent> component via the components prop, and not through imports within the MDX content. The use of useId() within MDX-components also doesn’t occur.
Therefore, it seems that my scenario effectively operates within a “clean room,” avoiding the conditions that trigger the React version conflicts. While my current approach works for my use case, I recognize that it’s not a general solution for all MDX implementations.
Hi @activemonkeys,
Your solution doesn’t touch the issue. Passing
Reactintoevaluateof@mdx-js/mdxis affectless, because theevaluateaccepts explicitly and only{Fragment, baseUrl, jsx, jsxDEV, jsxs, useMDXComponents}as runtime options. check hereAnd, typescript throws an error
Object literal may only specify known properties, and 'React' does not exist in type 'Readonly<EvaluateOptions>'.ts(2353)and warning us appropriately. You can disregard the error, and passReactintoevaluateexplicitly, but this doesn’t change anything.Meaningly, the
Reactwhich passed intoevaluateof@mdx-js/mdxis doing nothing.Why do you see that
CustomMDXworks ?Because, you didn’t test it against a MDX source which contains an import declaration for a React component.
Add
baseUrloption intoevaluate(otherwise imports don’t work)page.tsxTest.mjs(place it alongside withCustomMDX.tsx)And you will see the same error:
Thanks @talatkuyuk, within my own project I solved it without an external package. This is the code I’m using that works with Next.js 15.2.0: A React component that safely renders MDX content in Next.js applications by explicitly passing the React runtime to avoid version conflicts that cause errors in Next.js 15.2.0+. Maybe this will be helpful to you…