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

Impossible to use next-intl with Turbopack dev flag #1779

Open
3 tasks done
joshverd opened this issue Mar 11, 2025 · 2 comments
Open
3 tasks done

Impossible to use next-intl with Turbopack dev flag #1779

joshverd opened this issue Mar 11, 2025 · 2 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@joshverd
Copy link

Description

It seems like using the --turbo flag with the Nextjs dev server is currently not possible. There appears to be a mismatch with how the config file is resolved at different points in the dev server operation.

If I start the Next dev server without --turbo and the following config, everything works great:

/**
 * This works for Webpack
 * 
 * But NOT for starting the Turbo dev server
 */
const withNextIntl = createNextIntlPlugin(
  'i18n/request.ts',
);

But this does NOT work with turbo:

Error: [next-intl] Could not find i18n config at i18n/request.ts, please provide a valid path.

Second, I tried setting up another config file path, starting from src/ this time:

/**
 * This works for STARTING the Turbo dev server
 * 
 * But this will throw an error in layout.tsx when loading localhost:3000
 */
const withNextIntl = createNextIntlPlugin(
  'src/i18n/request.ts',
);

The dev server starts just fine, but once I load the project in the browser it throws an error in layout.tsx:

 ✓ Compiled / in 1295ms
 ⨯ Error: Couldn't find next-intl config file. Please follow the instructions at https://next-intl.dev/docs/getting-started/app-router
    at RootLayout (src/app/layout.tsx:20:31)
  18 |   children: React.ReactNode
  19 | }) {
> 20 |   const locale = await getLocale();

This could be related to how I structure my projects. All Nextjs frontend code is contained within the src/ dir. Check package.json in the repro repository to see the scripts I am using to start Next.

Verifications

Mandatory reproduction URL

https://github.com/joshverd/next-intl-bug-repro

Reproduction description

  1. Clone repro repository
  2. Run npm i
  3. Open src/next.config.ts
  4. Run npm run dev-turbo

Expected behaviour

I expect the dev server to 1) start properly and 2) render my layout.tsx and page.tsx files correctly.

@joshverd joshverd added bug Something isn't working unconfirmed Needs triage. labels Mar 11, 2025
@amannn
Copy link
Owner

amannn commented Mar 12, 2025

It seems like there are the following issues here:

  1. The path to i18n/request.ts needs to be relative (e.g. ./src/i18n/request.ts) or simply removed (since you use the default)
  2. The [directory] option for next dev doesn't work properly, you can resolve this by moving next.config.ts one folder up and calling next dev --turbo instead

I think what next-intl could do better is:

  1. Consistently handle relative paths (currently your input passes the validation but fails at runtime)
  2. Maybe support the [directory] option (I didn't even know this was supported, it's the first time I saw it)

But with the steps mentioned above you should be able to work around the issue for now.

@joshverd
Copy link
Author

Gotcha, that makes sense. I really appreciate the help here!

I tried digging through the next-intl code and debugging but I think Turbopack strips out any logging from node modules, which made it extremely difficult.

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

2 participants