"Not building properly" means that the project is not fully completing the build process. I've developed a simple blog project with dynamic SSR that pulls data from the Notion-API to generate static blog pages. Everything functions correctly when running in next dev
, but when attempting to build the project, it enters into an endless loop without displaying any errors.
One theory I have is as follows:
If my understanding of the sequence is correct, Next.js attempts to build the static sites during next build
. The dynamic site generation relies on an API coded within the same project, which sends requests to Notion to hide secrets. Since no local API is active during the build process, I suspect this may be causing the error I am encountering?
To demonstrate - here is the code for the pages to be generated:
import Head from 'next/head';
export default function Post( { postData, postBlocks } ) {
console.log( { postData, postBlocks } );
return (
<>
<Head>
<title>Placeholder</title>
<meta name="description" content="" />
</Head>
<h1>Placeholder</h1>
</>
)
}
// Get further info on the specific "Post" from Notion via my API
export async function getStaticProps( { params } ) {
const postDataRequest = fetch( `${ process.env.API_ROOT }/posts/${ params.id }` );
const postBlocksRequest = fetch( `${ process.env.API_ROOT }/blocks/${ params.id }` );
const [ postData, postBlocks ] = await Promise.all(
( await Promise.all( [ postDataRequest, postBlocksRequest ] ) )
.map( response => response.json() )
);
return {
props: { postData, postBlocks: postBlocks.results },
revalidate: 86400,
};
}
// Fetch all "Posts" from Notion via my API, retrieve their ID and generate a static route for each
export async function getStaticPaths() {
const req = await fetch( `${ process.env.API_ROOT }/posts?limit=999` );
const data = await req.json();
const paths = data.results.map( page => {
return { params: { id: page.id } };
} )
return {
paths,
fallback: false,
};
}
I've attempted starting the API locally and building the project in another terminal, but this also did not work. Have I overlooked something somewhere?
I have shared my project on GitHub for further examination.