NextJS Export Not Compatible with i18n Support
i18n Feature Cannot Be Used for Deployment in NextJS
Running NextJS 10 has been a great choice for me as it allows for Server-Side Rendering (SSR) and utilization of the i18n feature. Internationalized Routing is a new feature in NextJS 10 that has its own dedicated page.
However, when attempting to deploy, I encountered this error: i18n support is not compatible with next export. This issue is not addressed on the Internationalized Routing page.
Code Implementation
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 have created translation files that work based on conditions from the next router. Note: PT and EN are JSON files containing text content.
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
}
Using this function in my project:
{traducao().homeText.button_text}
It works well, detecting browser language and switching accordingly. I am using the following deployment script:
npm run deploy
"deploy": "npm run clean && npm run build && next export -o dist/"
Reproduction Steps
- Navigate to 'next.config.js'
- Create the i18n export
- Generate a Translate file that can detect browser language
- Import JSON files containing your site's text content
- Implement translations where needed
- Attempt deployment
Expected Outcome
The deployment should proceed smoothly without any issues.
Screenshots
System Details
- OS: Linux Ubuntu
- IDE: VSCode
- Next.js Version: 10
- Node.js Version: v15.3.0
- Deployment Method: next deploy