Here is the /[work]/page.js
export function generateStaticParams() {
return [
{ id: "work-1" }
{ id: "work-2" }
{ id: "work-3" }
]:
}
export default function WorkPage({ params }) {
const { id } = params;
...
and here is my nexjs.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export",
reactStrictMode: true,
images: { unoptimized: true },
};
export default nextConfig;
I am getting this error message:
Error: Page "/[work]/page" is missing param "/work-1" in "generateStaticParams()", which is required with "output: export" config.
2
Answers
It looks like there are a couple of issues with your code. The array returned by
generateStaticParams()
is missing commas between the objects, and thenext.config.mjs
file is correct as it is. Here is the corrected version of your code:/pages/[work]/page.js
next.config.mjs
Ensure that you have commas separating each object in the array returned by
generateStaticParams
. This should resolve the error you are encountering.To resolve the error "Page /[work]/page is missing param /work-1 in generateStaticParams(), which is required with output: export config", follow these steps:
Correct Project Setup for Next.js 14 with App Routing
1. Ensure Correct Syntax and Configuration:
generateStaticParams
function returns the correct structure.next.config.mjs
is accurate.2. Project Structure:
Ensure your project directory is correctly structured for the Next.js app router.
Solution
1. Corrected app/[work]/page.js
Ensure your
generateStaticParams
function and the page component handle dynamic routing properly:2. Example of a Work Component (
app/works/work1.js
)Ensure each work component is correctly defined and exported:
3. Configuration in
next.config.mjs
Ensure your Next.js configuration is correctly set up:
4. Directory Structure
Ensure your directory structure is correct for Next.js 14 app routing:
project-root/
Rebuild and Export
After making these changes, rebuild and export your Next.js project:
1. Build your project:
2. Export your project:
Summary
By ensuring the correct setup and structure, entering localhost:3000/work-1 should correctly mount the Work1 component. This approach resolves the error related to missing params in generateStaticParams when using output: export.