Next-i18next: namespacesRequired can not be defined for Error Page.

Created on 10 Jul 2019  路  7Comments  路  Source: isaachinman/next-i18next

Describe the bug

I am getting the warning for Error Page, and i didn't use any translation in Error Page.
Warn: You have not declared a namespacesRequired array on your page-level component: Error. This will cause all namespaces to be sent down to the client, possibly negatively impacting the performance of your app. For more info, see: https://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies
I tried to define namespacesRequired in Error Page, but next.js _error.js would override the returned parameter

Occurs in next-i18next version

0.37.0

Steps to reproduce

with appWithTranslation(myApp) in _app.js, Navigate to Error Page, and the above warning will appear, even with namespacesRequired defined.

Expected behaviour

The Warning is not expected.

Screenshots

N/A

OS (please complete the following information)

MBP 2017

Additional context

Add any other context about the problem here.

Most helpful comment

@timph Ah, fair point. Added with #407. In general it's quite easy to mess up the SSR localisation process without realising, so we try to provide as many useful warnings as possible to devs. The idea with the error page is that it is a pretty poor user experience to be given error feedback in a different language.

Also worth saying that we don't specifically check against the error page, but will warn you when you don't declare namespacesRequired on _any_ page. You always have the option to disable the warnings, though.

All 7 comments

That's exactly right. It's warning/reminding you to translate your error page.

Wait a minute. Error page is provided by Next.JS framework. How can you change a framework built-in error page? and what else we don't have control over.
We need way to stop this incessant warning, because there is something we don't care much about content (like error page)

You have not declared a namespacesRequired array on your page-level component: ErrorPage. This will cause all namespaces to be sent down to the client, possibly negatively impacting the performance of your app. For more info, see: https://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies

You have not declared a namespacesRequired array on your page-level component: ErrorPage. This will cause all namespaces to be sent down to the client, possibly negatively impacting the performance of your app. For more info, see: https://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies

You have not declared a namespacesRequired array on your page-level component: ErrorPage. This will cause all namespaces to be sent down to the client, possibly negatively impacting the performance of your app. For more info, see: https://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies

@timph Feel free to:

  1. Read the NextJs and next-i18next documentation thoroughly
  2. Disable strictMode in your config

I did.
The documentation for strictMode is not in
https://github.com/isaachinman/next-i18next#options
I found it in type.ds

@timph Ah, fair point. Added with #407. In general it's quite easy to mess up the SSR localisation process without realising, so we try to provide as many useful warnings as possible to devs. The idea with the error page is that it is a pretty poor user experience to be given error feedback in a different language.

Also worth saying that we don't specifically check against the error page, but will warn you when you don't declare namespacesRequired on _any_ page. You always have the option to disable the warnings, though.

I appreciate it, Isaac!

Thanks @isaachinman and @timph ,

Adding a pages/_error.js with namespacesRequired work fine for me.

Tho the NextJS doc say,

鈿狅笍 The pages/_error.js component is only used in production. In development you get an error with call stack to know where the error originated from. 鈿狅笍

Was this page helpful?
0 / 5 - 0 ratings