next.js: Root Layout Errors not triggering global-error.tsx in dev
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/intelligent-cdn-qkq9jc?file=%2Fnext.config.js%3A4%2C2
To Reproduce
- Start application in development mode
- Navigate to index page
- See that the contents of
global-error.tsxare not being displayed
Current vs. Expected behavior
I expect that the error throw in the root layout of the page is caught by the global-error.tsx file and that global error boundary is rendered. Currently the application fails when running next build and the developer error boundary is displayed when using next dev.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
Binaries:
Node: 20.6.1
npm: 9.8.1
Yarn: N/A
pnpm: 8.6.0
Relevant Packages:
next: 13.4.19
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Routing (next/router, next/navigation, next/link)
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 35
- Comments: 30 (9 by maintainers)
Commits related to this issue
- Display global-error along dev overlay during development (#75101) ### What Display `global-error.js` along with error overlay in development. When a runtime error occurred, you should be able to... — committed to vercel/next.js by huozhi 2 years ago
- Fixed `null is not an object (evaluating 't.parallelRoutes.get')` (#75360) ### Related issues 1. Fixes #69272 2. Fixes #69270 3. Fixes #67730 4. Relates to https://github.com/vercel/next.js/is... — committed to vercel/next.js by msereniti 2 years ago
This can probably be closed since the issue is tied to an expected, although not documented, behaviour.
But, while experimenting with error boundaries and
not-found.tsx’s api I found that sometimes, or I should say most of the time,global-error.tsxdoes not fire at all even in production… I just get the default client side exception UI.Let me know whether this should be placed in a new issue or not.
Here’s a reproduction repo: https://github.com/milovangudelj/tests And here’s the deployed example: https://tests.milovangudelj.com
You can trigger an error by clicking on the little red buttons placed throughout the demo.
I also have a phenomenon where “global-error.tsx” does not work even though I intentionally generate an error in “next 14.2.3”.
Ok, I tested it and it reliably renders the global error boundary (try it out, the link is still valid). BUT, it is never able to recover from it.
When calling
resetan error shows up in the console. Next tries to create the initial router state and at some point callsfillLazyItemsTillLeafWithHeadwhich in turn callsparallelRoutes.getresulting in a classicTypeError: Cannot read properties of null (reading 'get').same issue next.js: 14.2.3 react.js: 18.3.1 node.js: 18.20.2 npm: 10.5.0
I’ve updated my test repository to use
next@15.0.0-canary.197and it reliably renders all error boundaries (try it out). I don’t know when the fix has been implemented (it’s hard to pinpoint it given the sheer number of releases sincev14.0.5-canary.62).For anyone still having this issue try updating to the latest canary (
pnpm add next@canary) or take a look at how I implemented error handling in the repository and see if you’re doing something differently or in the wrong way.And if after that you’re still having trouble triggering and resetting error boundaries upvote this issue with a 👍 instead of commenting “+1 me too” to avoid clutter, unless you have new detailed information that could benefit the maintainers.
Peace ✌️
I’m on 15.0.1 and it’s not working.
I’m still seeing the error in 14.2.3
I added the following to the root layout:
Then performed the build.
Visiting any page throws an error but the
global-error.tsxpage is not presented. I get the following stack trace:^ This one I expect
^ These appear to be legit bugs
Wanted to report that I am also not able to trigger the
global-errorfile even in prod mode. Are there any restrictions as to file extensions like.jsinstead of.tsx. I get the below screen even when I have a global error file and am testingFor anyone stuck on this, until it is resolved: We were able to work around this by wrapping the entire app a route group, where the new root has no logic that can fail. This allowed use to have another error.tsx that can catch the errors.
@milovangudelj thanks for checking the updates, we’re looking into this error right now 🙏
+1
facing the same issue
next 14.2.5 react 18.3.1 react-dom 18.3.1
global-error.tsxdoes not render the contentThe global-error boundary is supposed only display in prod not in dev, then you can discover the error with dev error overlay to fix it. Having error in root layout will cause all app/ pages build failed.
The case here I think we can support global-error to render with app not-found routes, so it will error even you hit a bad route