I have the configuration of next-translate. But it doesnt load the getStaticProps
What version of this package are you using? 2.0.5
What operating system, Node.js, and npm version? Node: v18.14.0 npm:9.3.1 What happened? I have the configuration, and i dont wanna provide the getStaticProps because i wanna use the provided by the package but it doenst work What did you expect to happen? To add the getStaticProps Are you willing to submit a pull request to fix this bug? No
this is my next-config: ----- NEXT-CONFIG-----
const nextTranslate = require('next-translate-plugin');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.BUNDLE_ANALYZE === 'true',
});
const nextConfig = {
experimental: {
forceSwcTransforms: true,
},
reactStrictMode: true,
swcMinify: true,
};
module.exports = nextTranslate(withBundleAnalyzer(nextConfig));
----- NEXT-CONFIG-END-----
this in my i18n.js
---- i18n-JS----
module.exports = {
locales: ['es', 'en'], // Array with the languages that you want to use
defaultLocale: 'es', // Default language of your website
pages: {
'*': ['common'],
},
};
---- i18n-JS-END----
this is my [...uri].js
----[...URI]-JS---
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import useTranslation from 'next-translate/useTranslation';
import Link from 'next/link';
export default function Home() {
const { t, lang } = useTranslation('common');
return (
<div>
<main className={styles.main}>
<p className={styles.description}>{t('metaTitle')}</p>
<Link href="/home" locale="en">
<h2>Anglais</h2>
</Link>
<Link href="/inicio" locale="es">
<h2>Français</h2>
</Link>
</main>
</div>
)
}
export async function getStaticPaths() {
try{
const rutas = [
"/es/incio",
"/en/home"
];
const paths = rutas.map((item) => {
const secciones = item === null ? [] : item.split('/');
const rutas = secciones.filter((item) => item !== '');
if (rutas.length === 0) {
rutas.push('es');
}
const locale = rutas.shift();
return { params: { uri: rutas }, locale};
});
console.log(paths)
return {
paths: paths || [],
fallback: 'blocking',
};
} catch (error) {
console.log(error);
}
}
----[...URI]-JS-END---
This is my locales es:
---LOCALE-ES---
{
"metaTitle": "Next.js Localization with Next-Translate",
"title": "Welcome to my i18n NextJS application!",
"description": "I'm using the Next-Translate library to translate this page."
}
---LOCALE-ES-END---
This is my locale en:
---LOCALE-EN---
{
"metaTitle": "Next.js Localization with Next-Translate",
"title": "Welcome to my i18n NextJS application!",
"description": "I'm using the Next-Translate library to translate this page."
}
---LOCALE-EN-END---
Are your locales in /locales/es/common.json & /locales/en/common.json?
Yes my locales are in root fooler with this structure /locales --/es ----/common.json --/en ----/common.json
Not sure about the issue, can you try to remove the fallback blocking to verify if is for that? Otherwise, please provide a repo with the code to be easy to reproduce it
I remove the fallback, but the error dont change. -error Error: getStaticPaths was added without a getStaticProps in /[...uri]. Without getStaticProps, getStaticPaths does nothing i will crete it give me a time that i would have to delete some code to be able to share with you thanks.
https://github.com/EduardoGlober/Help
In the minimal reproducible proyect resolves like this: The problem is because the target is es6 if you change it to es5 works as expected. But in real proyects doesnt works.