I’m having an issue while trying to build a static website created with Next.js. The out folder is not being generated.
I think the problem is related to the SSR part of Next.js. Although it’s a small website, I am using dynamic routes, which are SSR-based. To resolve this, I tried creating a server-side component and passing the params to the actual client-side component that I wanted to render.
Here’s the current structure:
In the [id] folder, I have a file called page.tsx with the following code:
import { projects } from '@/data/projects';
import ProjectPage from './ProjectPage';
export const generateStaticParams = async () =>
projects.map((project) => ({
id: project.id,
}));
const fetchProjectData = async (id: string) => {
const project = projects.find((p) => p.id === id);
return project ?? null;
};
const Project = async ({ params }: { params: { id: string } }) => {
const project = await fetchProjectData(params.id);
if (!project) {
return (
<div className='w-full h-[100vh] flex justify-center items-center text-5xl font-bold'>
Project{' '}
<span style={{ color: 'var(--primary)', margin: '0 10px' }}>not</span>{' '}
found
</div>
);
}
return <ProjectPage project={project} />;
};
export default Project;
In the same folder, I also have another file called ProjectPage.tsx, which is a client-side component:
'use client';
const ProjectPage = ({ project }: ProjectPageProps) => {
...
};
I added output: ‘export’, in the next.config.ts file.
However, after running npx next build, I received the following output:
$ npx next build
▲ Next.js 14.2.26
Creating an optimized production build ...
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
✓ Generating static pages (11/11)
✓ Collecting build traces
✓ Finalizing page optimization
Route (app) Size First Load JS
┌ ○ / 29.3 kB 168 kB
├ ○ /_not-found 875 B 88 kB
├ ○ /contact 4.49 kB 99.9 kB
├ ○ /projects 548 B 94.5 kB
└ ● /projects/[id] 3.32 kB 143 kB
├ /projects/1
├ /projects/2
├ /projects/3
└ /projects/4
+ First Load JS shared by all 87.2 kB
├ chunks/117-057d17d2e788cd74.js 31.6 kB
├ chunks/fd9d1056-f1963c9e20a75983.js 53.7 kB
+ First Load JS shared by all 87.2 kB
├ chunks/117-057d17d2e788cd74.js 31.6 kB
+ First Load JS shared by all 87.2 kB
+ First Load JS shared by all 87.2 kB
├ chunks/117-057d17d2e788cd74.js 31.6 kB
├ chunks/fd9d1056-f1963c9e20a75983.js 53.7 kB
└ other shared chunks (total) 1.9 kB
+ First Load JS shared by all 87.2 kB
├ chunks/117-057d17d2e788cd74.js 31.6 kB
├ chunks/fd9d1056-f1963c9e20a75983.js 53.7 kB
+ First Load JS shared by all 87.2 kB
+ First Load JS shared by all 87.2 kB
+ First Load JS shared by all 87.2 kB
├ chunks/117-057d17d2e788cd74.js 31.6 kB
+ First Load JS shared by all 87.2 kB
+ First Load JS shared by all 87.2 kB
├ chunks/117-057d17d2e788cd74.js 31.6 kB
├ chunks/fd9d1056-f1963c9e20a75983.js 53.7 kB
└ other shared chunks (total) 1.9 kB
○ (Static) prerendered as static content
● (SSG) prerendered as static HTML (uses getStaticProps)
Has anyone encountered a similar issue with Next.js?