amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

Importing next.config.mjs to an api route (using the App router) causes the api route to crash (on Vercel) #1454

Closed joiglifberg closed 3 weeks ago

joiglifberg commented 3 weeks ago

Description

Importing next.config.mjs to an api route causes the api route to crash (on Vercel) with the following:

Error: Could not find i18n config at ./i18n/request.ts, please provide a valid path.

The reason for importing the config (in our case) was to check if the option trailingSlash was active or not.

Verifications

Mandatory reproduction URL

...

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Click on …
  3. See error: …

Expected behaviour

I expect the import to work as it did before using next-intl.

amannn commented 3 weeks ago

This is expected, importing from next.config.mjs is really not supported.

Alternatives:

  1. Define trailingSlash in a shared module that is consumed by next.config.mjs and your Route Handler
  2. Define an env param in next.config.mjs based on trailingSlash and read that in your Route Handler

Hope this helps!