lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.54k stars 380 forks source link

NextJS 14.2.5 and Lingui 4.11.x issues following example app as outline #1998

Closed itaie01 closed 1 month ago

itaie01 commented 2 months ago

Describe the bug Hello again, I have tried reimplementing i18n as per the swc example app provided. I seem to have run into an issue with setI18n, where I keep receiving the following errors.

This one in the NextJS dev console:

"The generated code contains 'async/await' because this module is using "topLevelAwait". However, your target environment does not appear to support 'async/await'. As a result, the code may not run as expected or may cause runtime errors."

and this one in the browser:

Error: Cannot read properties of undefined (reading 'bind')

When I add config.experiments = { topLevelAwait: true }; to the NextJS webpack config, this error goes away, but the pages of the website never build, even in dev mode. I have ensured that the i18n object is not null/undefined, so I am not sure what the issue at hand is.

Would appreciate if anyone can help dissect this issue.

vonovak commented 2 months ago

Hello and thanks for reporting, Firstly, this issue doesn't seem to be related to Lingui itself but rather to tooling configuration.

Can you please create a Minimal, Reproducible Example that we can see the issue with? The most effective reproducible examples are created by starting a new project from scratch and adding in only the necessary pieces to reproduce the issue. Without this, the issue is not actionable from my end.

Alternatively, you can get around without the top-level await - either turn getI18nInstance to async and await its result in the components, or use lingui compile to get the compiled catalog ahead of time.

Thank you 🙂