How do I test the "global-error.js" page locally?
Unanswered
Bald Eagle posted this in #help-forum
Bald EagleOP
I tried throwing an error in the component and throwing an error on a click of a button.
I also tried running
I also tried running
npm run build
and npm run start
instead of npm run dev
7 Replies
@Bald Eagle I tried throwing an error in the component and throwing an error on a click of a button.
I also tried running `npm run build` and `npm run start` instead of `npm run dev`
Global-error.js only catches errors thrown in the RootLayout, throw an error in there and you’ll see it
@Plague Global-error.js only catches errors thrown in the RootLayout, throw an error in there and you’ll see it
Bald EagleOP
For some reason it just displays the error in the console of the browser, but does not show the error.js or global-error.js page
@Bald Eagle For some reason it just displays the error in the console of the browser, but does not show the error.js or global-error.js page
Need to be prod mode. You can use either a dynamic layout (export const revalidate = 0) or use react devtool to trigger an error
Bald EagleOP
I thought that running
npm run build
and npm run start
puts the app in prod modewhere would I need to add
export const revalidate = 0
?Bald EagleOP
Hey @joulev sorry to bother you, your tip with
In the docs it says that
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#revalidating-data
revalidate
did help and I was able to see the error pages locally, but I was wondering about why this works?In the docs it says that
revalidate
is used to purge the Data Cache, how does export const revalidate = 0
put you into Prod mode??https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#revalidating-data
@Bald Eagle Hey <@484037068239142956> sorry to bother you, your tip with `revalidate` did help and I was able to see the error pages locally, but I was wondering about why this works?
In the docs it says that `revalidate` is used to purge the Data Cache, how does `export const revalidate = 0` put you into Prod mode??
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#revalidating-data
It doesn’t put you into prod mode. It ensures that the code is not run during build so the error is caught during runtime by the boundary file rather than caught during build causing a build error.