next-i18next: `next export` does not work

Describe the bug When doing a next export to built a static page, i get the following error:

TypeError: Cannot read property '0' of undefined
    at /Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/next-i18next/dist/hocs/app-with-translation.js:155:68
    at Array.filter (<anonymous>)
    at _callee$ (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/next-i18next/dist/hocs/app-with-translation.js:154:61)
    at tryCatch (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/regenerator-runtime/runtime.js:288:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/regenerator-runtime/runtime.js:114:21)
    at asyncGeneratorStep (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
    at /Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
    at new Promise (<anonymous>)

To Reproduce Steps to reproduce the behavior:

  1. Clone or download this repository
  2. In terminal do cd example
  3. Install dependencies: yarn
  4. I had to install next-i18next as well: yarn add next-i18next
  5. Check if it runs in dev: yarn run dev -> Works
  6. Check if it builds: yarn run next build -> Works
  7. Check if it exports: yarn run next export -> Fails

Expected behaviour A static version of the app/page should be built.

OS (please complete the following information):

  • Device: MacBook Pro (15-inch, 2017)
  • Browser: Chrome Version 70.0.3538.110

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

This is fixed with #15.

Now, doing next export in a next-i18next project will result in a clientside-only React application.

No future plans to support any kind of custom export process with locale subdirs.

If someone full export: Those two issues contain some hints: https://github.com/zeit/next.js/issues/2665 https://github.com/zeit/next.js/issues/5509

Hey @isaachinman,

Thanks for your prompt reply and for the great work on all things i18next.

My maybe naïve expectation was, that the export would write translated strings to static html. The resulting app/site would then have a set of pages for the defaultLanguage and another set of pages for every additional language inside a lang-folder (e.g. de).

I’m pretty sure there once was a react-i18next example for nextjs that exported like that.

But thinking about it a little more, i see that language switching might prove a bit tricky in that scenario in terms of keeping the route and not linking to /.

I will search for that example and see if it really exports as described above.

Thanks again and best regards!

Till

Interesting issue. I protected a couple of the language logic areas with simple if statements and got export working just fine.

That said, this project isn’t really friendly to next export as it specifically requires some server side logic to detect language, fetch translation files, and so on. There’s no way to do SSR translations without some server logic.

I’m curious as to how you expected this to work? Perhaps I’m missing something?

The only workable “solution” I can think of is to have the server render nothing, and the client can successfully fetch translated content as needed. This would depend upon NextJs exposing some sort of env var to indicate that an export is being run.