Next.js Discord

Discord Forum

Error building next js application

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Hello, I'm trying to upload a nextjs application to github but i'm having issues with running npm run build.
At first I was able to build the website and upload it to github but got an error saying I had to use output: export in the next config.
I fixed the error but now i'm having problem with running npm run build. This is the error i'm getting: Error: Page "/[levelId]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.

What is the issue here? This is the code from my [levelId] page:
"use client";
import React from "react";
import levelsData from "../LevelsData";
import { usePathname } from "next/navigation";

const Page = ({ params }: { params: { levelId: string } }) => {
  const currentLink = usePathname();
  const levelId = Number(currentLink.substring(1)) - 1;
  const levelData = levelsData[levelId];

  return (
    <>
      <div className="max-w-[1300px] px-3 mx-auto flex flex-col items-center min-h-screen bg-base-200 rounded-t-md">
        <h1>#{params.levelId} Demon</h1>
        <h1 className="text-2xl text-neutral-content font-bold">
          {levelData.label}
        </h1>
        <p className="text-lg text-base-content">By {levelData.creator}</p>
        <div className="w-[80%]">
          <iframe
            className="w-full h-[270px] md:h-[450px] lg:h-[600px]"
            src={levelData.embed}
            title="YouTube video player"
            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
          ></iframe>
        </div>
        <div className="container">
          <p className="text-center">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Ad, tenetur
            tempora laborum omnis nesciunt voluptate accusamus ut repellat nam
            eius quia quos illo maiores obcaecati aliquid officiis pariatur
            ducimus recusandae consectetur vero! Velit eius, voluptatum rerum
            neque reprehenderit natus debitis! Nostrum, placeat magnam enim sint
            unde distinctio tempora mollitia dolor.
          </p>
          <div className="flex flex-col items-center py-4">
            <h1 className="font-bold text-2xl text-primary">Records</h1>
            <ul>
              <li>Player 1: 00:00:00s</li>
              <li>Player 2: 00:00:00s</li>
              <li>Player 3: 00:00:00s</li>
              <li>Player 4: 00:00:00s</li>
            </ul>
          </div>
        </div>
      </div>
    </>
  );
};

export default Page;

3 Replies

@Giant panda Hello, I'm trying to upload a nextjs application to github but i'm having issues with running npm run build. At first I was able to build the website and upload it to github but got an error saying I had to use output: export in the next config. I fixed the error but now i'm having problem with running npm run build. This is the error i'm getting: `Error: Page "/[levelId]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.` What is the issue here? This is the code from my [levelId] page: "use client"; import React from "react"; import levelsData from "../LevelsData"; import { usePathname } from "next/navigation"; const Page = ({ params }: { params: { levelId: string } }) => { const currentLink = usePathname(); const levelId = Number(currentLink.substring(1)) - 1; const levelData = levelsData[levelId]; return ( <> <div className="max-w-[1300px] px-3 mx-auto flex flex-col items-center min-h-screen bg-base-200 rounded-t-md"> <h1>#{params.levelId} Demon</h1> <h1 className="text-2xl text-neutral-content font-bold"> {levelData.label} </h1> <p className="text-lg text-base-content">By {levelData.creator}</p> <div className="w-[80%]"> <iframe className="w-full h-[270px] md:h-[450px] lg:h-[600px]" src={levelData.embed} title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" ></iframe> </div> <div className="container"> <p className="text-center"> Lorem ipsum dolor sit amet consectetur adipisicing elit. Ad, tenetur tempora laborum omnis nesciunt voluptate accusamus ut repellat nam eius quia quos illo maiores obcaecati aliquid officiis pariatur ducimus recusandae consectetur vero! Velit eius, voluptatum rerum neque reprehenderit natus debitis! Nostrum, placeat magnam enim sint unde distinctio tempora mollitia dolor. </p> <div className="flex flex-col items-center py-4"> <h1 className="font-bold text-2xl text-primary">Records</h1> <ul> <li>Player 1: 00:00:00s</li> <li>Player 2: 00:00:00s</li> <li>Player 3: 00:00:00s</li> <li>Player 4: 00:00:00s</li> </ul> </div> </div> </div> </> ); }; export default Page;
like the error said, you need to export generateStaticParams function in [levelId]/page.tsx
generateStaticParams

The generateStaticParams function can be used in combination with dynamic route segments to statically generate routes at build time instead of on-demand at request time.