amannn / next-intl

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

Update doc (with-i18n-routing.mdx) #1360

Closed Git-I985 closed 1 month ago

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2024 8:28am
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2024 8:28am
vercel[bot] commented 1 month ago

@Git-I985 is attempting to deploy a commit to the next-intl Team on Vercel.

A member of the Team first needs to authorize it.

Git-I985 commented 1 month ago

LGTM ))) @amannn

image

amannn commented 1 month ago

Hey @Git-I985, many thanks for your proposal to add a note to the docs to cover an error you've encountered!

The warning block is unfortunately very prominent and I haven't seen anybody run into this so far, I so I think I'd rather not include this.

Can you share though what you were trying to import that caused the error for you?

amannn commented 1 month ago

Closing due to inactivity …

Git-I985 commented 2 weeks ago

@amannn

you know, I tried to import the redirects section/field from next.config.js to my sitemap, and im getting such errors

⨯ Error: 

Could not locate i18n request config for next-intl.

These paths are supported by default:
- ./(src/)i18n/request.{js,jsx,ts,tsx}
- ./(src/)i18n.{js,jsx,ts,tsx}

Alternatively, you can specify a custom location in your Next.js config:

const withNextIntl = createNextIntlPlugin(
'./path/to/i18n/request.tsx'
);

 at /usr/app/.next/server/chunks/9670.js:1:4177
 at /usr/app/.next/server/chunks/9670.js:1:4515
 at /usr/app/.next/server/chunks/9670.js:1:4641
 at 12499 (/usr/app/.next/server/chunks/6852.js:1:2217)
 at t (/usr/app/.next/server/webpack-runtime.js:1:143)
 at 84936 (/usr/app/.next/server/chunks/6852.js:4:8681)
 at t (/usr/app/.next/server/webpack-runtime.js:1:143)
 at 70523 (/usr/app/.next/server/app/(service-pages)/(sitemaps)/proxy-sitemap-site.xml/route.js:1:1062)
 at t (/usr/app/.next/server/webpack-runtime.js:1:143)
 at t (/usr/app/.next/server/app/(service-pages)/(sitemaps)/proxy-sitemap-site.xml/route.js:1:1840)

My toughts about why it happen:

// next.config.js

const withNextIntl = createNextIntlPlugin();

// ...

const nextConfig = {
  poweredByHeader: false,
  compress: false,
  output: 'standalone',
  // ... 
  redirects: [...],
  env: {},
}

module.exports = withNextIntl(nextConfig);

then i have such sitemap route

src/app/(service-pages)/(sitemaps)/proxy-sitemap-site.xml/route.ts

and im importing/using next.config.js into it via

import nextConfig from '../../../../next.config';

// some stuff here ...

const redirects = (await (nextConfig as NextConfig).redirects?.()) ?? [];

FYI my sitemap is dynamic next page FYI im getting this error in build/production mode

so, and when im requesting sitemap page in my browser im getting error above, because of implementation of createNextIntlPlugin

Now i temp solved this with exporting all redirects stuff to another js module, redirects.config.js, and im using this module where i need, in next.config.js and sitemap etc

And I tried to warn other people with my PR that they need to be careful with this imports from next.config.js due to the implementation of createNextIntlPlugin

PS sorry for my language, im not native english speaker

amannn commented 2 weeks ago

Now i temp solved this with exporting all redirects stuff to another js module, redirects.config.js, and im using this module where i need, in next.config.js and sitemap etc

That's what I'd recommend too. Importing from next.config.js into app code sounds like a source of bugs, beyond the issue with next-intl you've encountered. Thanks for sharing your solution here!