generateStaticParams
Unanswered
Siamese Crocodile posted this in #help-forum
Siamese CrocodileOP
Hey everyone! I'm trying to create a dynamic route at /referral/[code]/page in my Next.js app, and I'm running into an issue. When I set output: 'export' in my next.config.js, I get this error during build:
Error: Page "/referral/[code]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.
If I remove the output: 'export', the build works, but when I run the app in Docker, I get a 404 — path not found.
Has anyone faced this before or know how to fix it? Any help would be appreciated!
Error: Page "/referral/[code]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.
If I remove the output: 'export', the build works, but when I run the app in Docker, I get a 404 — path not found.
Has anyone faced this before or know how to fix it? Any help would be appreciated!
26 Replies
@Siamese Crocodile Hey everyone! I'm trying to create a dynamic route at /referral/[code]/page in my Next.js app, and I'm running into an issue. When I set output: 'export' in my next.config.js, I get this error during build:
Error: Page "/referral/[code]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.
If I remove the output: 'export', the build works, but when I run the app in Docker, I get a 404 — path not found.
Has anyone faced this before or know how to fix it? Any help would be appreciated!
the
output: 'export'
creates a static export hence it needs to know all the pages at build time@Yi Lon Ma the `output: 'export'` creates a static export hence it needs to know all the pages at build time
Siamese CrocodileOP
I tried with 'output: standalone and undefined both but still getting same error.
@Siamese Crocodile I tried with 'output: standalone and undefined both but still getting same error.
how are you running your application in standalone mode?
Siamese CrocodileOP
I created pages in src/app where i am creating dynamic param page. there I am getting issue. standalone and undefined was just hit and try can you please help me, that how I can fix this issue?
I will need to see your code
Siamese CrocodileOP
can we join google meet?
sorry but I don't join any meets
please share your code here
Siamese CrocodileOP
How do I can share here?
post your code here?
Siamese CrocodileOP
"use client"
import { useParams } from "next/navigation"
import { useRouter } from "next/navigation"
import { useEffect } from "react"
import { useDispatch } from "react-redux"
import { setUserDetails } from "@/libs/features/auth/authSlice"
export default function ReferralPage() {
const params = useParams()
const dispatch = useDispatch()
const router = useRouter()
useEffect(() => {
if (params?.code) {
dispatch(setUserDetails({ referralCode: params?.code as string }))
}
router.replace("/")
}, [params, dispatch, router])
return null
}
import { useParams } from "next/navigation"
import { useRouter } from "next/navigation"
import { useEffect } from "react"
import { useDispatch } from "react-redux"
import { setUserDetails } from "@/libs/features/auth/authSlice"
export default function ReferralPage() {
const params = useParams()
const dispatch = useDispatch()
const router = useRouter()
useEffect(() => {
if (params?.code) {
dispatch(setUserDetails({ referralCode: params?.code as string }))
}
router.replace("/")
}, [params, dispatch, router])
return null
}
this is only page where i am facing the issue
also send screenshot of your file structure
Siamese CrocodileOP
remove the output:export
Siamese CrocodileOP
removed
now try
Siamese CrocodileOP
after remove its work on local but when i deploy on server with docker build. getting this error
show me your docker config
Siamese CrocodileOP
FROM node:22.14.0 AS base
# Set working directory
WORKDIR /app
# Install dependencies
# COPY package.json ./
# RUN wget https://pmc-media.s3.us-west-2.amazonaws.com/socialfi/node_modules.zip
# RUN unzip node_modules.zip
# RUN rm -rf node_modules.zip# Copy the rest of the application
COPY . .
RUN npm install --ignore-scripts
# Build the Next.js application
RUN npm run build
# Production stage
# FROM node:20.18.3 AS production
# Set working directory
# WORKDIR /app
# Create a non-root user
# RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy built files and dependencies from the base stage
# COPY --from=base /app/node_modules ./node_modules
# COPY --from=base /app/.next ./.next
# COPY --from=base /app/public ./public
# COPY --from=base /app/package.json ./package.json
# Set ownership and permissions
# RUN chown -R node:node /app
# Switch to non-root user
# USER node
# Set environment variables
ENV NODE_ENV=production
# Expose port 3000
EXPOSE 3000
# Start the application
CMD ["npm", "run", "start"]
# Set working directory
WORKDIR /app
# Install dependencies
# COPY package.json ./
# RUN wget https://pmc-media.s3.us-west-2.amazonaws.com/socialfi/node_modules.zip
# RUN unzip node_modules.zip
# RUN rm -rf node_modules.zip# Copy the rest of the application
COPY . .
RUN npm install --ignore-scripts
# Build the Next.js application
RUN npm run build
# Production stage
# FROM node:20.18.3 AS production
# Set working directory
# WORKDIR /app
# Create a non-root user
# RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy built files and dependencies from the base stage
# COPY --from=base /app/node_modules ./node_modules
# COPY --from=base /app/.next ./.next
# COPY --from=base /app/public ./public
# COPY --from=base /app/package.json ./package.json
# Set ownership and permissions
# RUN chown -R node:node /app
# Switch to non-root user
# USER node
# Set environment variables
ENV NODE_ENV=production
# Expose port 3000
EXPOSE 3000
# Start the application
CMD ["npm", "run", "start"]
this looks fine
Siamese CrocodileOP
Yeah
try to clear your docker cache and rebuild the image again
Siamese CrocodileOP
i tried with as well
Siamese CrocodileOP
Resolved issue.