Next.js Discord

Discord Forum

Mayday: Error: Insufficient params provided for localized pathname.

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I'm working with dynamic and non dynamic localized pathnames, and when I visit the user profile page it gives the error presented in the screenshot.

Moreover, I am also having issue with switching the locale, where I can't get the locale switcher to work correctly with both non dynamic localized paths and dynamic localized paths.

Here is the documentation I'm following:
https://next-intl-docs.vercel.app/docs/routing/navigation
https://next-intl-docs.vercel.app/docs/routing/middleware

The files related to the process are the following:

- next.config.mjs (here I am doing some rewrites for the user profile page)
- src/i18n.ts
- src/middleware.ts
- src/navigation.ts
- src/app/[locale]/user/[id]/client.tsx
- src/app/[locale]/user/[id]/page.tsx
- src/app/[locale]/user/[id]/fetch-user-data.tsx
- components/top-navigation-bar/language-selector.tsx
- components/top-navigation-bar/top-navigation-bar.tsx
- components/sidebar/job-seeker-sidebar.tsx

Let me know what part of the code you'd like to see from the list above.

In the meantime here's a bit of code from my navigation.ts file so that you can make an idea of how I have it set-up

import { createLocalizedPathnamesNavigation, Pathnames } from "next-intl/navigation";

export const locales = ["en", "ro"] as const;
export type Locale = typeof locales;
export const localePrefix = "always";

export type LocalizedPathnames = Pathnames<typeof locales> & {
  '/user/[id]': { en: string; ro: string };
};

export const pathnames: LocalizedPathnames = {
  "/": "/",
  "/login": { en: "/login", ro: "/autentificare" },
  "/signup": { en: "/signup", ro: "/inregisrare" },
  "/user/[id]": { en: "/user/[id]", ro: "/utilizator/[id]" },
};

export const {
  Link,
  redirect,
  usePathname,
  useRouter,
  getPathname,
} = createLocalizedPathnamesNavigation({ locales, pathnames });

174 Replies

Im scared of intl myself, but try this maybe @Sun bear https://github.com/amannn/next-intl/issues/643
lmao
Sun bearOP
It's not my thread but was the closest issue related to what I'm experiencing.
Thing is I can get rid of that error if I want to, I can revert back the code to how I had it when the only issue I had was with the locale switcher.
If I do that then the profile page loads just fine, but then I get into this issue where it won't correctly switch to the correct dynamic path when I switch the language while on the profile page, as in it would go from:

/en/user/id to /ro/user/id instead of /ro/utilizator/id and viceversa
Giant panda
so the error is while switching locale ?
@Giant panda so the error is while switching locale ?
Sun bearOP
Yes, and it's not an error, cause the language does switch but it doesn't switch correctly, as in it only switches the locale parameter (from /en to /ro) but it doesn't switch the parameter after it which is the /user to /utilizator or whatever user is called in other languages.
And that causes the website to throw a 404 error, page does not exist.
if possible, provide a min repro repo
Giant panda
share your switcher code
if possible
The most relevant part of the switcher code is this one:
{locales.map((locale) => (
            <li key={locale} className="hover:bg-hover-element">
              <Link
                href={{ pathname: pathName }}
                locale={locale}
              >
And the documentation also shows an example here
And here
Giant panda
I think it is not receiving the correct href prop
@Giant panda I think it is not receiving the correct href prop
Sun bearOP
Could the issue be coming from one of these pages then ?

- src/app/[locale]/user/[id]/client.tsx
- src/app/[locale]/user/[id]/page.tsx
- src/app/[locale]/user/[id]/fetch-user-data.tsx

Or does it come from

- src/navigation.ts
- components/top-navigation-bar/language-selector.tsx
probably from language-selector
@Giant panda probably from language-selector
Sun bearOP
Any idea what how I need to modify it then ?
Giant panda
I'm looking for fix
:lolsob:
Sun bearOP
No worries I'll wait.
@Anay-208 if possible, provide a min repro repo
Sun bearOP
If that would help I can do that too. Just let me know which files you'd like the mini repo to contain based on the files list from my thread at the top and I'll do it.
the files which are causing the error
that also helps with nextjs issue reports, if its confirmed to be a issue with nextjs
Once I get a min repro repo, I'll try to fix the err
Giant panda
i think you missing some files
@Giant panda i think you missing some files
Sun bearOP
Just let me know which ones and I'll add them.
Giant panda
package.json
Sun bearOP
Added
@Sun bear https://github.com/meJohnnyRobert/Next-Intl-Debug/tree/main
I'll look into this tomorrow
@Anay-208 I'll look into this tomorrow
Sun bearOP
Alright, thank you very much. If there's anyhting missing just let me know and I'll add it.
In the meantime I'll try and see if I can solve it with the other guys in here.
Ping me and lmk incase it is resolved, otherwise I'll start looking into this
@Giant panda i think you missing some files
Sun bearOP
I've just updated the sidebar in the repo, I noticed it was using the old userId path instead of user/[id]. Previously I had the folder called [userId] instead of [id].
The error is still there when trying to access the profile page but at least I know it's not that. I thought the error was caused because I forgot to update the sidebar component but it looks like that's not what's causing it.
Giant panda
sorry for late response but app is not starting probably need to remove my files
Sun bearOP
Hmm
Giant panda
in my side
Sun bearOP
No worries I'll wait, in case something is missing just let me know and I'll add it to the repo.
Sun bearOP
My bad, for some reason I've posted only a small part of the error. Here's the whole screenshot.
Mind you, the jobs page loads just fine, and the locale switching works just fine for that page, which is not a dynamic page. This error pops up when I try to access the /user/[id] page.
Giant panda
also add tsconfig
😭
@Giant panda also add tsconfig
Sun bearOP
Added!
@Giant panda so error is while clicking ?
Sun bearOP
Yup, when I click on that button.
Giant panda
remove the supabase code for now because it won't work locally
wait
@Giant panda remove the supabase code for now because it won't work locally
Sun bearOP
But it did work previously, before I updated the routing.
Giant panda
no i mean in my side also you're missing messages folder with its locales json
Giant panda
or I should just add some demo data for testing
You know what I think I'll have to invite you to my private repo cause you won't be able to test this without supabase since you won't be able to access the profile page.
Unless you can do it, in which case I can just give you my user id
Normally the user profile should be publicly accessible for now but i'm not sure if it actually would work without the supabase stuff working on your side.
Sun bearOP
@Giant panda let me know if there's anything you need from my side. I can also invite you to the private repo where supabase should work on your side and you won't have to bother with dummy data.
Giant panda
sorry for late response i think we don't need supabae data for now
@Giant panda https://pastebin.com/z0bekiU3
Sun bearOP
Giant panda
yeah I was about to mention that error
I removed alot of code to make it runnable
// src/middleware.ts

import { locales, pathnames, localePrefix, getPathname } from "./navigation";
import createMiddleware from "next-intl/middleware";

export default createMiddleware({
  pathnames,
  localePrefix,
  locales,
  defaultLocale: "en",
});

export const config = {
  matcher: ["/", "/(ro|en)/:path*", "/((?!_next|_vercel|.*\\..*).*)"],
};
@Giant panda I removed alot of code to make it runnable
Sun bearOP
Yeah sorry for that, I had to have the code I have for the supabase stuff. Mind you I do have a working version of the codebase in which the my profile button works, basically that version uses the following path in navigation.ts:
 "/user/:userId": { en: "/user/:userId", ro: "/utilizator/:userId" },

And in the sidebar it uses the following code:

const JobSeekerSidebar: React.FC<JobSeekerSidebarProps> = () => {
  const router = useRouter();
  const pathname = usePathname();
  const t = useTranslations("sidebar");
  const { user } = useUserSessionStore();
  const locale = useLocale() as 'en' | 'ro'; // Casting locale to the expected type

  const handleButtonClick = (path: keyof typeof pathnames, params?: { [key: string]: string }) => {
    // Get the localized path based on the current locale
    let localizedPath = getPathname({
      locale,
      href: path,
    });

    // If params are provided, replace the placeholders in the path
    if (params) {
      localizedPath = Object.keys(params).reduce((acc, key) => {
        return acc.replace(`:${key}`, params[key]);
      }, localizedPath);
    }

    // Navigate to the constructed path
    router.push(localizedPath);
  };

return (
 <IconButton
            icon={<FaRegUser />}
            label={t('myProfile')}
            onClick={() =>
              user?.id
                ? handleButtonClick('/user/:userId', { userId: user.id })
                : handleButtonClick('/user/:userId')
            }
            isActive={pathname === `/user/${user?.id}`}
          />
)

This version leads to the correct locale and user id basically works correctly, but the issue with it is that when I switch the language while on the user profile page through the language switcher it only switched the /locale/ segment.
Giant panda
"Yeah sorry for that, I had to have the code I have for the supabase stuff. Mind you I do have a working version of the codebase in which the my profile button works, basically that version uses the following path in navigation.ts:" oh I thought error is while onClick event
Sun bearOP
Well with the current version of the code, which is the one I shared with you via the github repo yes, but with the older version of the code where the user id folder is called [id] instead of [userId] the profile button works just fine, based on the locale.
If you want I can switch back to that version and we can instead try to figure what's set-up worng with the language selector in that version.
This way I suppose we don't have to deal with the current issue.
Giant panda
hmm
it's 1:48 AM here. is it ok if we can discuss this problem later ?
@Giant panda it's 1:48 AM here. is it ok if we can discuss this problem later ?
Sun bearOP
Sure thing. I've also recorded a quick video in order to give a bit more insight into the other version of the code that I have that I told you about, you can check it out later if you want to.
Sun bearOP
And here's an overview explanation of the issue
- Warning: Loud popping sound between 01:00 - 01:05, not sure what happened there.
- Also, at one point in the video it actually worked correctly then it stopped working again, lol
(at around 08:50) using the codebase version which uses the [id] folder.
@Sun bear just wondering if your issue is resolved before I start working on it.
We didn't make any progress since yesterday, I just recorded those videos to better explain what happens. If you need anything from me in the meantime please let me know

(if I'm offline I'll reply as soon as I see your message)
Sun bearOP
@Anay-208 are you still looking into this ?
I'm planning to look into it as soon as I get free
@Anay-208 I'm planning to look into it as soon as I get free
Sun bearOP
Can you give me an estimate of when that might be ? Just for me to make an idea of what to expect, will it be this weekend or sometime else (if you know your schedule ofc)
I'm expecting in few mins
Ok Now I 'm looking at it, since I just completed the task I needed to do rn
@Anay-208 I'm expecting in few mins
Sun bearOP
That's great, thank you very much. I was asking because I'd like to be online in case you'll have questions or need something, rather than having you wait for me, then me waiting for you and so on.

I really recommend checking out the 2nd video I posted above, it gives more context to it.
alright
this is the only bug, right?
@Anay-208 this is the only bug, right?
Sun bearOP
Yes, at least for how the code is working right now. If you need access to the whole project just let me know and i'll invite you to my private repo (so that you can have supabase working)
@Anay-208 Click to see attachment
Sun bearOP
Yeah, I think it's better to invite you to the private repo, you can dm me with you're github e-mail. This way you'll have everything working on your side as well.
admin@anayparaswani.me
Sun bearOP
Coppied, you can delete it if you want to.
not needed, its public(on my site)
Sun bearOP
Awesome. I've invited you, I'll send you a dm with the .env file as well.
There's 2 branches I'm using, "user-profile-implementation" and the secondary one, the only difference between the two is minor differences in the navigation.ts file and the sidebar component. The 2nd video explains it.
Sure, as long as it doesn't
contain any production sensitive data
Sun bearOP
No worries, the website isn't operational yet.
Sun bearOP
I'd say the user-profile-implementation branch.
Cause that's the one which uses the [id] folder and form what I understand that's how it's normally done.
user-profile-implementation
ok
Sun bearOP
Yup
I actually just wanted the [Minimal Reproduction Repo](https://nextjs-faq.com/minimal-reproduction-repository), I'll see if I can check the error directly from this repo
@Sun bear Can I know the route where you are facing this issue
@Anay-208 <@998405690718703696> Can I know the route where you are facing this issue
Sun bearOP
Yes, it's the my profile route
You can reach that route by first going to the jobs page (the sidebar isn't visible otherwise)
I think you'll have to create a dummy account for this one, after that I can delete it from the database.
So that you can log in and access that page.
the country selector is getting bugged FYI
Sun bearOP
Ohh it might be from the light mode I'm usually using dark mode, let me test that.
Hmm for me it works, are you using the localhost or the website ?
Also I've only tested it in Chrome, Safari and Arc, not sure how it looks like with other browsers.
localhost
I m on chrome only
on profile page, what do I have to do to reproduce, as I changed the language and everything's working fine
@Sun bear
@Anay-208 I m on chrome only
Sun bearOP
Hmm strange, for me it works
lets keep this aside for now
Can we talk about this error
How do I exactly reproduce it
That's where the issue should be happening
Sun bearOP
Alright, see that "ro/user" ?
It should be "ro/utilizator" because the path name needs to be localized
And if you go to the jobs page, switch the language to english, then go back to the profile page and try to switch to romanian it will take you to /en/utilizator and you will get a 404 error because of that.
In navigation.ts you will be able to see how the paths should look like.
And I am also doing a rewrite for the profile page in the next.nonfig.mjs file if you look.
if I switch to romanian
you can see the url when i hover
@Anay-208 it takes me to `/en/user`
Sun bearOP
My bad, i meant this
As in go to the jobs page, switch to Romanian (not english)
Then try to go to my profile
That's when the issue should happen
Am I doing anything wrong here in reproducing the err
You're switching to english before going to the my profile page, instead of letting the language stay romanian.
ahh got it
Sun bearOP
And in navigation.ts you can see how I have it set-up.
And here is how the documentation for next-intl says to do it, I've tried following that
https://next-intl-docs.vercel.app/docs/routing/navigation
there is an issue between the files navigation.ts & language-selector.ts
I'm still seeing
Sun bearOP
I have no idea what the issue is, I've tried debugging it with both Claude Opus and GPT 4/4o.
For like 2 weeks
Whatever it is it's either a bug either very hard to catch using AI.
(unless you're a programmer and know exactly what to look for and how to debug it, which I'm not)
I'll give you further info about it tomorrow
Its 2 am gotta sleep now
Sun bearOP
No worries, have a good night and we can talk about it tomorrow then, or when you have a bit of time to look more into it.
Thank you very much for trying to help me with this, I really appreciate it.
if possible, just remind me to debug it as soon as you see this message. (ping me)
@Anay-208 if possible, just remind me to debug it as soon as you see this message. (ping me)
Sun bearOP
It's okay we can leave it for tomorrow, I couldn't make it earlier today to ping you.
And if possible, create a min repro repo
@Anay-208 And if possible, create a min repro repo
Sun bearOP
I've created a mini repo if you remember, if there's something missing now that you have access to the main repo as well you can pretty much add it yourself since that's also faster since it's on your machine and we don't have to move back and forth..
Sun bearOP
You know what, nevermind. I'll find a solution, thank you for trying to help.
we are at 166 messages. please wrap up soon.
you basically have to recreate the error
Giant panda
@Anay-208 he already created a mini repo
@Anay-208 .
Giant panda
just remove the unnecessary imports
There might be more breaking changes even after doing that, hence I prefer to get the actual minimum repro repo
Giant panda
then you should have said that earlier