We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently it is not possible to use serverSideTranslations in combination with getInitialProps to translate 500 error messages.
If I try to use getInitialProps serverSideTranslations I receive following error:
serverSideTranslations
ModuleNotFoundError: Module not found: Error: Can't resolve 'fs'
// pages/500.js export default function Error({ err }) { return <div>Error happened..</div> } export const getInitialProps = async ({ locale, err }) => { return { err, ...(await serverSideTranslations(locale, ['common', 'layout'])) } }
The text was updated successfully, but these errors were encountered:
Ok I solved it on a second attempt, in case anyone bumps into it here my _error.tsx page:
import { GetStaticProps, NextPage } from 'next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' const Error: NextPage<{ statusCode?: number }> = ({ statusCode }) => { return ( <> <div> {statusCode ? `An error ${statusCode} occurred on server` : 'An error occurred on client'} </div> </> ) } Error.getInitialProps = async ({ err, res }) => { // eslint-disable-next-line no-nested-ternary const statusCode = res ? res.statusCode : err ? err.statusCode : 404 return { statusCode } } export const getStaticProps: GetStaticProps = async ({ locale }) => ({ props: { ...(await serverSideTranslations(locale, ['common', 'layout'])) } }) export default Error
Sorry, something went wrong.
Which is weird, because Next.js instantly tells me I am not able to use getInitProps AND getStaticProps within a page component.
No branches or pull requests
Is your feature request related to a problem? Please describe.
Currently it is not possible to use serverSideTranslations in combination with getInitialProps to translate 500 error messages.
Additional context
If I try to use getInitialProps
serverSideTranslations
I receive following error:The text was updated successfully, but these errors were encountered: