next.js: i18n support is not compatible with next export. (SSR - NextJS 10)

i18n support is not compatible with next export.

NextJS dont run the deploy with i18n

Im using nextJS 10, and the main reason that i choose next 10, is that i can do SSR and use the i18n. Internationalized Routing its a new next js 10 feature and have a page only to tha feature.

But when im gonna do a deploy, this error appears: i18n support is not compatible with next export. Theres nothing about this in internationalized routing page.

My code

next.config.js

const withImages = require('next-images')
const path = require('path')

module.exports = withImages({
    esModule: false,
    i18n: {
        locales: ['en-US', 'pt-BR', 'pt-PT', 'es-ES'],
        defaultLocale: 'pt-BR',
      },
});

I created a translate archive that make the condition with next router obs: PT and EN are JSON files with text

import * as pt from "./pt";
import * as en from './en';
import { useRouter } from "next/router"

export const traducao = () =>{
  let routes = useRouter();

  let translate;
 
    if (routes.locale == 'pt-PT' || routes.locale == 'pt-BR') {
      translate = pt.default;
    } else {
      translate = en.default;
    }
  
  return translate 
}

And the i just use in my project like a function:

{traducao().homeText.button_text}

Work well, recognizes the browser language and switch. Im using deploy script

npm run deploy
"deploy": "npm run clean && npm run build && next export -o dist/"

Steps to reproduce

  1. Go to ‘next.config,js’
  2. create the i18n export
  3. create a Translate file that recognizes the browser language
  4. import JSONs files with your site text
  5. Use where you want
  6. Try to deploy

Expected behavior

Its just suppose to work fine and Deploy normal.

Screenshots

image image image image

System information

  • OS: Linux Ubuntu
  • IDE: VSCode
  • Version of Next.js: 10
  • Version of Node.js: v15.3.0
  • Deployment: next deploy

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 15 (3 by maintainers)

Most upvoted comments

i had similar problem. can anyone tell me how to fix it?

Unfortunately not. I had a big problem with this, and unfortunately after a lot of searching I couldn’t find anyone who was able to solve it.

I think it’s really bad that one of the main tools in NEXT doesn’t support something that important. simply shameful

If you are deploying on a platform that supports Next.js like Vercel you do not need to call next export and will not encounter the error, also note calling next export disables pages from using getServerSideProps or other SSR features. next export support was not mentioned in the initial i18n RFC since next export is opting out of Next.js server routing support.

I understand. However I did not try to use the export. I just used the deploy script (npm run deploy). This script already comes with the project. What can I do to deploy without export. I’m deploying through Debian, on a company server.

@lucasReghiniM you might have a look at: https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd

Can anyone tell me if it works?

@bakydev for sure it works… an example here: https://github.com/adrai/next-language-detector/tree/main/example

And a production example of localistars.com here: https://github.com/localistars/localistars-landing

cool, I’m gonna try out, btw thank you for the fast answer