0

I'm trying to integrate Lingui with a NextJS App router app, and I'm getting this error:

Error occurred prerendering page "/u". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Lingui: Attempted to call a translation function without setting a locale.
Make sure to call `i18n.activate(locale)` before using Lingui functions.
This issue may also occur due to a race condition in your initialization logic.
    at C._ (C:\Users\x\x\frontend\.next\server\chunks\319.js:1:16367)
    at w (C:\Users\x\x\frontend\.next\server\app\u\page.js:1:10830)
    at nF (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:46843)
    at nH (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:48618)
    at nH (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:64688)
    at nW (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:67762)
    at nz (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:65337)
    at nY (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:71193)
    at nX (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:69876)
    at nW (C:\Users\x\x\frontend\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:76:68029)
Export encountered an error on /u/page: /u, exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null
error Command failed with exit code 1.

I've tried initializing Lingui both like the demo in the Lingui repo (although my app is not as simple, so it cannot be 1:1 implemented like there), and in few other places, yet I cannot find a way to avoid this error.

Where am I supposed to initialize it for it to be universally visible for the builder?


Edit: It seems that the problem is caused by a client components, if they have any translations, that could be evaluated at the build time. Server components are unaffected, code in useEffect or in code blocks guarded by if (window != undefined) also seems to not break the build.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.