aralroca / next-translate

Next.js plugin + i18n API for Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
2.62k stars 208 forks source link

Error: Invariant: attempted to hard navigate to the same URL #942

Open bartek2341 opened 1 year ago

bartek2341 commented 1 year ago

What happened? Hi, I just connected my app to the error tracker and noticed a lot of errors only on localized versions of my website: https://[domain-name]/[locale].

error

Source of all errors: {snip} dLocale.addLocale(router.asPath,router.locale)))throw Error("Invariant: attempted to hard navigate to the same URL ".concat(url," ").concat( {snip}

Example log: log

It seems that after navigation to the same url it can't find the [locale].json file. I've tested navigating to the same page multiple times using the link component both on production and development, but I haven't noticed any errors/warnings in the console.

I was using Next.js v12.2.4 but the error still persists after upgrading to v13. Does anyone know if next-translate can cause this behavior or is it more related to a bug on the next.js side and I should open a topic there.

Thanks

What version of this package are you using? 1.6.0

What operating system, Node.js, and npm version? Win 10, Node 18.12.0, npm 9.1.1

next.config.js ``` const nextTranslate = require("next-translate"); const { withSentryConfig } = require("@sentry/nextjs"); const moduleExports = { ...nextTranslate(), sentry: { hideSourceMaps: true, }, }; const sentryWebpackPluginOptions = { silent: true, }; module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions); ```
i18n.json ``` { "locales": ["pl", "en", "es", "ru", "tr", "zh", "hi", "fr", "ar", "bn", "pt", "id", "de", "it"], "defaultLocale": "pl", "localeDetection": false, "pages": { "*": ["common"], "/": ["index"], } } ```
aralroca commented 1 year ago

We need more details. Can you provide a reproducible example?