Skip to content
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

Using all the Steps in the Docs yet I still see the same error "Error: Couldn't find next-intl config file. Please follow the instructions" #639

Closed
EfstathiadisD opened this issue Nov 16, 2023 · 6 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@EfstathiadisD
Copy link

Description

I am using the latest release of next-intl. I was previously using 2.x and was working fine. I did all the Steps described in this page as the error message suggests.

Here are the files I have:

import createI18nMiddleware from "next-intl/middleware";

export default createI18nMiddleware({
	locales: ["en", "el", "de"],
	defaultLocale: "en",
});

export const config = {
	matcher: ["/", "/((?!api|_next|.*\\..*).*)"],
};
import { getRequestConfig } from "next-intl/server";

export default getRequestConfig(async ({ locale }) => ({
	messages: (await import(`../locales/${locale}.json`)).default,
}));
const { withSentryConfig } = require("@sentry/nextjs");
const withNextIntl = require('next-intl/plugin')();
const path = require("path");

/** @type {import('next').NextConfig} */
const nextConfig = {
	pageExtensions: ["ts", "tsx"],
	compiler: {
		emotion: true,
	},
	experimental: {
		esmExternals: true,
		externalDir: true,
	},
	sentry: {
		disableServerWebpackPlugin: true,
		disableClientWebpackPlugin: true,
	},
	transpilePackages: [
		"@***/components/*",
		"@***/constants/*",
		"@***/cookies/*",
		"@***/theme/*",
		"@***/utils/*",
	],
};

module.exports = withSentryConfig(withNextIntl(nextConfig), {
	org: "****",
	project: "***",
	authToken: process.env.SENTRY_AUTH_TOKEN,

	disableLogger: true,
	hideSourceMaps: true,
	transpileClientSDK: true,
});
import { redirect } from "next/navigation";

export default function RootPage() {
	redirect("/en");
}
import "./globals.css";

import type { PropsWithChildren } from "react";

type RootLayoutProps = PropsWithChildren<Record<string, never>>;

function RootLayout({ children }: RootLayoutProps) {
	return children;
}

export default RootLayout;
import type { PropsWithChildren } from "react";

import { Inter } from "next/font/google";
import { notFound } from "next/navigation";

import { NextIntlClientProvider } from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";

import { ThemeProvider } from "@midgard/components/ThemeProvider/ThemeProvider";

import { getMessages } from "../../clients/i18n";
import { ApolloProvider } from "../../components/ApolloProvider";

const ALL_LOCALES = ["en", "el", "de"];
const inter = Inter({ subsets: ["latin", "greek"], display: "swap" });

type LocaleLayoutProps = PropsWithChildren<{
	params: { locale: string };
}>;

export function generateStaticParams() {
	return ALL_LOCALES.map((locale) => ({ locale }));
}

export async function generateMetadata({ params }: LocaleLayoutProps) {
	const t = await getTranslations({ locale: params.locale });

	return {
		title: t("LOCALE.METADATA.TITLE"),
		description: t("LOCALE.METADATA.DESCRIPTION"),
	};
}

async function LocaleLayout({ children, params }: LocaleLayoutProps) {
	if (!ALL_LOCALES.includes(params.locale)) {
		return notFound();
	}

	const messages = await getMessages(params.locale);

	unstable_setRequestLocale(params.locale);

	return (
		<html suppressHydrationWarning={true} lang={params.locale}>
			<head>
				<meta
					name="format-detection"
					content="telephone=no, date=no, email=no, address=no"
				/>
				<meta name="color-scheme" content="light dark" />
			</head>
			<body suppressHydrationWarning className={inter.className}>
				<ApolloProvider>
					<NextIntlClientProvider messages={messages}>
						<ThemeProvider>{children}</ThemeProvider>
					</NextIntlClientProvider>
				</ApolloProvider>
			</body>
		</html>
	);
}

export default LocaleLayout;

And it should theoretically work. I deleted node_modules, disabled other middleware removed Sentry in case it conflicted somewhere, yet nothing.

The issue seems to be with the matcher. With the one you are providing all my routes are 404, and with the one that matches mine, throw the above error.

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-26fy8s?file=%2Fsrc%2Fmiddleware.ts%3A7%2C4&layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clp1ml0um00093b5xtznwcm9y%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clp1ml0ul00033b5xh3pzt6ve%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clp1ml0ul00063b5xts0ianf5%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clp1ml0um00083b5xw5ej96sc%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clp1ml0ul00033b5xh3pzt6ve%2522%253A%257B%2522id%2522%253A%2522clp1ml0ul00033b5xh3pzt6ve%2522%252C%2522activeTabId%2522%253A%2522clp1mlcsd005z3b5x4vv5w82n%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clp1ml0ul00023b5xfqsqtbgb%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Fmiddleware.ts%2522%252C%2522id%2522%253A%2522clp1mlcsd005z3b5x4vv5w82n%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%257D%252C%2522clp1ml0um00083b5xw5ej96sc%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clp1ml0um00073b5xm5bawiod%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252Fen%2522%257D%255D%252C%2522id%2522%253A%2522clp1ml0um00083b5xw5ej96sc%2522%252C%2522activeTabId%2522%253A%2522clp1ml0um00073b5xm5bawiod%2522%257D%252C%2522clp1ml0ul00063b5xts0ianf5%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clp1ml0ul00043b5xuwzh19r6%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clp1ml0ul00053b5x4xs7m1qa%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522start%2522%257D%255D%252C%2522id%2522%253A%2522clp1ml0ul00063b5xts0ianf5%2522%252C%2522activeTabId%2522%253A%2522clp1ml0ul00043b5xuwzh19r6%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. See error: …

The error stems from the path matcher. In real project, we might have more complicated stuff. What should we use then? Is it a bug in next-intl?

Expected behaviour

When I use a matcher, it should match the routes we have in our applications and not show 404, and should be able to use next-intl as well.

@EfstathiadisD EfstathiadisD added bug Something isn't working unconfirmed Needs triage. labels Nov 16, 2023
@amannn
Copy link
Owner

amannn commented Nov 17, 2023

I think your matcher is off and doesn't match /en.

The matcher that the docs suggest for localePrefix: 'as-needed' works for me in your CodeSandbox (fixed version). If you need something more specialized, make sure that it matches all relevant pathnames in your app.

Hope this helps!

@amannn
Copy link
Owner

amannn commented Nov 23, 2023

Closing this due to inactivity.

@amannn amannn closed this as completed Nov 23, 2023
@EfstathiadisD
Copy link
Author

Sorry for this, but I tried a brand new repo. Copying one to one from the examples file on you repo. It just doesn't work. I am not sure what the problem is. It just doesn't work. The code is the same, I even copied the pathnames strategy to be sure.

What am I doing wrong? The error keeps saying it cannot find the next-intl config. Where is that config? The main diff with the examples I see, is I need the NextIntlClientProvider. The examples don't use it. So, they don't pass it the messages. Any help would be appreciated. I can even invite you for a bit on the private repo.

Or even a simple example that has the NextIntlClientProvider and something close to my setup would be great. Thank you in advance..

@EfstathiadisD
Copy link
Author

EfstathiadisD commented Nov 30, 2023

Here is an example. It is 1-2-1 what you have in the examples. Can you take a look please? I am sure it should be working. What am I doing wrong?

@CrazyOrr
Copy link

Change your next.config.cjs to next.config.js should fix it. Took me a long time to figure this out too.

@lhguerra
Copy link

lhguerra commented Jan 22, 2024

I'm not using cjs but still get the same issue. The docs are very confusing, the client way of setting up aks for no next.config alterations and also no special config files are needed. But it is impossible to make it work without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

4 participants