Next.js Discord

Discord Forum

Confusion with generateStaticParams | Next 14.1.4

Unanswered
Naeemgg posted this in #help-forum
Open in Discord
to use dynamic routes with tauri we need to use generateStaticParams, It was working fine with one params /users/[userId] I was generating it on page.tsx but now I have to do it like this /users/[userId]/[project]/[projectId]
My question is how to generate Params like these??
I tried generating many ways but still ended up getting this error
Server Error
Error: Page "/users/[userId]/[project]/page" is missing param "/users/2/2" in "generateStaticParams()", which is required with "output: export" config.

This error happened while generating the page. Any console logs will be displayed in the terminal window.

What is the problem here??

58 Replies

@Naeemgg Now unable to even goto /users/[userId] 😭
oh you need to export a generateStaticParams in /users/[userId]/page.tsx too
in all nested route I need to export correct?
//users/[userId]/page.tsx 
export async function generateStaticParams() {
  return [
    { userId: '1' },
    { userId: '2' }
  ]
}
@Naeemgg in all nested route I need to export correct?
yes every page.tsx
in [userId] I need to return userIDs
yes
in [userId]/[project]/page.tsx
userIds + project or just project??
I tried this
 return [{ userId: "blabla",
         project:"vercel"
       },{...})
its not working giving the same error
@Naeemgg its not working giving the same error
what is the error now?
Server Error
Error: Page "/users/[userId]/[project]/page" is missing param "/users/2/1" in "generateStaticParams()", which is required with "output: export" config.

This error happened while generating the page. Any console logs will be displayed in the terminal window.
tried this also
 return [{project:"vercel"
       },{...})
yes
for dev purpose I'm returning an array map
for(i=0;i<10;i++)
like this
@Naeemgg for(i=0;i<10;i++)
can you show the code on generateStaticParams?
  const users = []
  for(let i=0; i<10;i++){
   racks.push({id:i.toString()})
  }
      
       return users.map((user) => ({
         userId: user.id,
        project:user.id
       }))
/user/[usderId]
export const generateStaticParams = async()=>{
   
   const users = []
   for(let i=0; i<10;i++){
    users.push({id:i.toString()})
   }
       
        return users.map((user) => ({
          userId: user.id,
        }))

      
}
@Ray what is `racks` here?
ohh sorry it was users
@Naeemgg ohh sorry it was users
ok can you show the generateStaticParams on /users/[userId]/[project]/page?
yes
export const generateStaticParams = async()=>{
   
   const users = []
   for(let i=0; i<10;i++){
    users.push({id:i.toString()})
   }
       
        return users.map((user) => ({
          //userId: user.id,
          project:user.id
        }))

      
}
tried commenting and uncommenting stuff
still getting the same error
@Naeemgg already tried
what is the error message?
do you have some link go to /users/2/1?
yes
  return users.map((user) => ({
          userId: user.id,
          project:user.id
        }))

this doesn't generate /users/2/1
this generate
/users/0/0
/users/1/1
/users/2/2
/users/3/3
....
you need to add {userId: 2, project: 1 } in the array
But I have links
let me show it to you
Ahh its too big component
I have on first page 10 users with
<Link href={'/users/${userId}'}>{username}</Link>
After clicking on users I can see there projects and click on them to see different project IDs
Are you getting my point or have I lost you?
@Ray
@Naeemgg Are you getting my point or have I lost you?
so have you got it working?
Noooooo
Tried many many things but still not working
@Naeemgg Tried many many things but still not working
West African Lion
Having quite a similar issue with Next.js 14.2.2.
Have you maybe found a solution?
@West African Lion Having quite a similar issue with Next.js 14.2.2. Have you maybe found a solution?
I got to know one thing about Tauri which is it hates SSR so if you want to use searchParams or params my humble advice would be to go with react
West African Lion
I have tried digging in, and...
When I set:
export const dynamicParams = false;

in my page.tsx, I get in the first (nested) if-statement:
staticPaths = pathsResult.staticPaths;
fallbackMode = pathsResult.fallbackMode;
hasFallback = typeof fallbackMode !== "undefined";
if (this.nextConfig.output === "export") {
  const page = components.page;
  if (fallbackMode !== "static") {
    throw new Error(`Page "${page}" is missing exported function "generateStaticParams()", which is required with "output: export" config.`);
  }
  const resolvedWithoutSlash = (0, _removetrailingslash.removeTrailingSlash)(resolvedUrlPathname);
  if (!(staticPaths == null ? void 0 : staticPaths.includes(resolvedWithoutSlash))) {
                    throw new Error(`Page "${page}" is missing param "${resolvedWithoutSlash}" in "generateStaticParams()", which is required with "output: export" config.`);
  }
}
Basically, fallbackMode is set to false and seems to correspond to the value of dynamicParams.

However, if I set it to "static" - which I shouldn't according to the documentation - I get in the next if-statement.
(Also, doing so is a hard error when running npm run build)