vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.91k stars 26.87k forks source link

Custom _error.js page context is missing locale info #31771

Open vkosovskikh opened 2 years ago

vkosovskikh commented 2 years ago

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

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

talamcol commented 1 year ago

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.