next.js
next.js copied to clipboard
Custom _error.js page context is missing locale info
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 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
- Create nextjs project with
typescript
template - Include i18n options in
next.config.js
file. - Create custom
_error.tsx
file as described in nextjs docs Custom Error Page -
npm run build
-
npm run start
- Get unhandled exception client side
- 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.