having issue with next/root-params
Unanswered
omar_ab(@om4rAb) posted this in #help-forum
I am learning how to add Internationalization from Nextjs docs and so far I kinda got stuck at where it talks about using next/root-params but I do get this error
The export lang was not found in module [next]/root-params.js [app-rsc] (ecmascript).
The module has no exports at all.
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.
The export lang was not found in module [next]/root-params.js [app-rsc] (ecmascript).
The module has no exports at all.
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.
22 Replies
@omar_ab(@om4rAb) I am learning how to add Internationalization from Nextjs docs and so far I kinda got stuck at where it talks about using **next/root-params** but I do get this error
*The export lang was not found in module [next]/root-params.js [app-rsc] (ecmascript).
The module has no exports at all.
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.*
root params are not the ones that you looking for. You have a dynamic segment (and that’s correct). Then you need to access those dynamic params. You can do so like this:
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <div>My Post: {slug}</div>
}
change the “slug” to your “lang” and like that you can access it ^^
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <div>My Post: {slug}</div>
}
change the “slug” to your “lang” and like that you can access it ^^
@B33fb0n3 root params are not the ones that you looking for. You have a dynamic segment (and that’s correct). Then you need to access those dynamic params. You can do so like this:
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <div>My Post: {slug}</div>
}
change the “slug” to your “lang” and like that you can access it ^^
but then i gotta keep prop drilling down to every component
like they show in this example
to avoid the prop drilling
Florida White
That the way I do mine I use params await it the get the id or value from the params and use it to search or query what you need it for
@omar_ab(@om4rAb) can you delete your .next folder and retry?
@B33fb0n3 <@930989277867827201> can you delete your .next folder and retry?
hi, i have done it multiple times but no effect,
Somehow I managed to get it work, i had to have only one root layout and inside it i shouldv added a generateStaticParams otherwise it will throw an error
what I am currently running into is, for example, I am on /fr/home clicking a products link takes me to /products instead of /fr/products and that is the issue with every link
I wanna rely solely on the proxy and append the fr/en to every request but based on Gemini response I got this
do you suggest anything ?
Somehow I managed to get it work, i had to have only one root layout and inside it i shouldv added a generateStaticParams otherwise it will throw an error
what I am currently running into is, for example, I am on /fr/home clicking a products link takes me to /products instead of /fr/products and that is the issue with every link
I wanna rely solely on the proxy and append the fr/en to every request but based on Gemini response I got this
While this makes your component code cleaner and faster to write, it introduces significant performance and SEO trade-offs that make it unsuitable for production-grade e-commerce applications.do you suggest anything ?
@erikcodez have you tried next-intl for i18n? (i think i18n is your goal, am I correct?)
yes you are right
I just wanted to go with what docs suggests without installing any package
I just wanted to go with what docs suggests without installing any package
so far iv been able to make the translation work im just stuck in the last issue I mentioned here https://nextjs-forum.com/post/1546237065824309259#message-1546605520306053231
@B33fb0n3 can you share your middleware (proxy)?
it looks like this
what do you think of it ?
import process from "node:process";
import { type NextRequest, NextResponse } from "next/server";
import { updateSession } from "@/lib/supabase/proxy";
import { createSerClient } from "@/lib/supabase/server";
const locales = ['fr', 'en']
export async function proxy(request: NextRequest) {
const BASE_URL = process.env.NEXT_PUBLIC_LOCALHOST_URL;
const url = request.nextUrl.pathname;
const sp = await createSerClient();
const { data: user } = await sp.auth.getClaims();
const isOwner = user?.claims.app_metadata?.user_role === "owner";
if(!url.startsWith('/dashboard')){
const isPathHasLocal = locales.some(
(locale) => url.startsWith(`/${locale}/`) || url === `/${locale}`
)
if (!isPathHasLocal) {
request.nextUrl.pathname = `/${locales[1]}/${url}`;
return NextResponse.redirect(request.nextUrl);
}
}
if(url.startsWith('/dashboard')){
if(!user || !isOwner){
return NextResponse.redirect('/');
}
return NextResponse.next();
}
return await updateSession(request);
}
export const config = {
matcher: [
"/sign-in",
"/dashboard/:path*",
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
],
};what do you think of it ?
@omar_ab(@om4rAb) it looks like this
import process from "node:process";
import { type NextRequest, NextResponse } from "next/server";
import { updateSession } from "@/lib/supabase/proxy";
import { createSerClient } from "@/lib/supabase/server";
const locales = ['fr', 'en']
export async function proxy(request: NextRequest) {
const BASE_URL = process.env.NEXT_PUBLIC_LOCALHOST_URL;
const url = request.nextUrl.pathname;
const sp = await createSerClient();
const { data: user } = await sp.auth.getClaims();
const isOwner = user?.claims.app_metadata?.user_role === "owner";
if(!url.startsWith('/dashboard')){
const isPathHasLocal = locales.some(
(locale) => url.startsWith(`/${locale}/`) || url === `/${locale}`
)
if (!isPathHasLocal) {
request.nextUrl.pathname = `/${locales[1]}/${url}`;
return NextResponse.redirect(request.nextUrl);
}
}
if(url.startsWith('/dashboard')){
if(!user || !isOwner){
return NextResponse.redirect('/');
}
return NextResponse.next();
}
return await updateSession(request);
}
export const config = {
matcher: [
"/sign-in",
"/dashboard/:path*",
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
],
};
what do you think of it ?
you cant directly mutate the request pathname from nextUrl. Do this instead:
const response = NextResponse.redirect(
new URL(
`/${locale}${pathname.startsWith('/') ? '' : '/'}${pathname}${search}`,
request.url,
),
);@B33fb0n3 you cant directly mutate the request pathname from nextUrl. Do this instead:
tsx
const response = NextResponse.redirect(
new URL(
`/${locale}${pathname.startsWith('/') ? '' : '/'}${pathname}${search}`,
request.url,
),
);
ok I will try that, also what do u think of the whole proxy, u think this can be shipped to production ?
@omar_ab(@om4rAb) ok I will try that, also what do u think of the whole proxy, u think this can be shipped to production ?
Yea.. the matched can be deduplicated and I personally wouldn’t use supabase, but rest looks fine for me
Yellow Wagtail
I tried root params as well, but it doesn't work; it is still an experimental feature. I think you need to configure it in the
next.config.ts file.@Yellow Wagtail I tried root params as well, but it doesn't work; it is still an experimental feature. I think you need to configure it in the `next.config.ts` file.
no, it was a root layout issua that's why, if ur still trying to make it work I can help u
@B33fb0n3 Yea.. the matched can be deduplicated and I personally wouldn’t use supabase, but rest looks fine for me
Thank youu iv been able to make everything work now, iv moved from proxy hadnling the locales to just passing props and using the usecontext to pass deep down ,
the i18n is working soo fine
a record of the result so far ahahha https://streamable.com/66sesv gimme ur pov
the i18n is working soo fine
a record of the result so far ahahha https://streamable.com/66sesv gimme ur pov
@omar_ab(@om4rAb) no, it was a root layout issua that's why, if ur still trying to make it work I can help u
Yellow Wagtail
great! but when i tried. i got a similar error as in the ss.