-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
homepage 404 error, when using nextjs13.4 version #1111
Comments
Same here. Latest example only works if I am already in e.g. |
In my case must declare explicitly a locale in the URL to view the homepage, if no locale is provided it shows a 404. Using app router with: Any way to have homepage working on default language? |
We are investigating a better way to fix that, because now i18n has some trobles with the middleware (issue vercel/next.js#49883), but for now can be solved adding a import { NextRequest } from 'next/server';
import { redirect } from 'next/navigation';
import i18nConfig from '../../i18n';
export async function GET(request: NextRequest) {
const userPreferredLanguage =
request.headers.get('accept-language')?.split(',')?.[0] ??
i18nConfig.defaultLocale;
const lang = i18nConfig.locales.includes(userPreferredLanguage)
? userPreferredLanguage
: i18nConfig.defaultLocale;
return redirect(`/${lang}${request.nextUrl.pathname.toLowerCase()}`);
} src/app
├── [lang]
│ │── layout.tsx
│ ├── loading.tsx
│ ├── page.tsx
└── route.ts |
I have the same problem using the regular Next Pages, any way to solve it? Doesn't happen on localhost, but it does on Vercel, if I click on any link on the page doesn't happen and only occurs on the home page. next 13.4.4 |
I think only happens when |
How can I achieve that in the pages router? |
This problem is not related with |
Should I open another issue then? I'm getting a production error on Vercel using the pages router. Only happens on the homepage and if the person is using one of my locales specified in the i18n.json without being the default one, doesn't happen on localhost or if the person uses a link in my site that points to the home. Live site: Repo: |
I have the same problem using the App Router, homepage 404 error. next 13.4.12 |
Hi again, I found that this workaround works when server is already up but once you shut down and start server again it throws ERR_TOO_MANY_REDIRECTS because of |
I am still getting this error in production at my homepage in the
When I go to With route.ts:
With i18n.json:
And in the RootLayout:
Am I forgetting something? versions:
|
Did you solve this issue? I have it in |
No, it still gives a 404 unluckily. |
I did solve it with what @aralroca said but with these specific versions of
|
For me even with this versions, I keep getting:
|
In my personal use case i saw that there's sooooo many variants of english and i don't really care about the minor differences between spelling for route.ts
i18n.js
looking at your error |
I changed the configuration to match exactly what you provided, but I still encounter the same error. When I set the defaultLocale to The console log, as you pointed out, indeed returns Interestingly, this problem is unique to the next-translate package. I tried switching to |
if you're getting
|
Even with that I am getting a 500 internal server error:
|
hit me up at abraham@itule.me then we'll jump on a call, i'll help you fix it. |
Hey, thanks for the offer but I switched to |
Same problem here. Is it a nextjs bug? Know anybody when it will be fixed? |
Any idea what is that error? I have a build that works locally but fails on Vercel with that exact same error. I tried on both node My Next version is I used the strategy proposed here: https://www.izoukhai.com/blog/implement-internationalization-i18n-in-next-13-actually-working The error I get is: Error: Invariant: The detected locale does not match the locale in the query. Expected to find 'default' in '/fr' but found 'fr'}
at I18NProvider.fromQuery (/var/task/node_modules/next/dist/server/future/helpers/i18n-provider.js:70:27)
at Object.fn (/var/task/node_modules/next/dist/server/next-server.js:973:106)
at Router.execute (/var/task/node_modules/next/dist/server/router.js:315:44)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextNodeServer.runImpl (/var/task/node_modules/next/dist/server/base-server.js:615:29)
at async NextNodeServer.handleRequestImpl (/var/task/node_modules/next/dist/server/base-server.js:546:20) I tried to look at fromQuery(pathname, query) {
const detectedLocale = query.__nextLocale;
// If a locale was detected on the query, analyze the pathname to ensure
// that the locale matches.
if (detectedLocale) {
const analysis = this.analyze(pathname);
// If the analysis contained a locale we should validate it against the
// query and strip it from the pathname.
if (analysis.detectedLocale) {
if (analysis.detectedLocale !== detectedLocale) {
throw new Error(`Invariant: The detected locale does not match the locale in the query. Expected to find '${detectedLocale}' in '${pathname}' but found '${analysis.detectedLocale}'}`);
}
pathname = analysis.pathname;
}
}
return {
pathname,
detectedLocale,
inferredFromDefault: query.__nextInferredLocaleFromDefault === "1"
};
} So this error shouldn't even happen because I added the If we translate the error: throw new Error(`Invariant: The detected locale does not match the locale in the query. Expected to find '${detectedLocale}' in '${pathname}' but found '${analysis.detectedLocale}'}`); I have:
It seems the issue is with the The requested URL |
Can you tried in 3.0.0-canary.1 version? (both, next-translate & next-translate-plugin). Thanks |
What version of this package are you using?
What operating system, Node.js, and npm version?
npm : 8.5.1
nodejs: v18.16.0
What happened?
After using npx create-next-app@latest to create a project and only adding the next-translate library, the home page cannot be accessed and a 404 error is displayed.
Whether it is /ja /en /zh or / cannot be accessed, a 404 error is displayed
What did you expect to happen?
I hope the normal home page can be displayed
Are you willing to submit a pull request to fix this bug?
I don't think I can do it
with i18n.js and next.config.js
i18n.js
next.config.js
whatever i add experimental.appDir or remove it still get 404 error
and with the nextjs config
The text was updated successfully, but these errors were encountered: