I want to internationalize custom _error.js page. Expected to get locale from page context in Error.getInitialProps but got undefined.
Expected Behavior
_error.tsx
Error.getInitialProps = (context: NextPageContext) => {
const { locale } = context; // expected to get locale here, but got undefined
...
return { statusCode };
}
To Reproduce
1) Create nextjs project with typescript template
2) Include i18n options in next.config.js file.
3) Create custom _error.tsx file as described in nextjs docs Custom Error Page
4) npm run build
5) npm run start
6) Get unhandled exception client side
7) Check locale value in Error.getInitialProps
Is there any workaround available? I just tested it in Next 13 and the issue still persists. It only happens for server-side errors on my end. 404 works fine.
What version of Next.js are you using?
12.0.1
What version of Node.js are you using?
14.17.4
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
local dev environment
Describe the Bug
I want to internationalize custom
_error.js
page. Expected to getlocale
from page context inError.getInitialProps
but gotundefined
.Expected Behavior
_error.tsx
To Reproduce
1) Create nextjs project with
typescript
template 2) Include i18n options innext.config.js
file. 3) Create custom_error.tsx
file as described in nextjs docs Custom Error Page 4)npm run build
5)npm run start
6) Get unhandled exception client side 7) Check locale value inError.getInitialProps