What are you trying to accomplish
I would like to run builder.init
in the SSG block of my Next.js site (in getStaticProps
) without throwing an error. That way, I can deploy multiple Builder websites with a single Next.js application.
Screenshots or video link
As you can see in the screenshot below, my website’s page loads fine. However, in the console, I get an error that the “Builder SDK has not been initialized properly”. I don’t think that this is a valid error as the site works. I’d like to understand why I shouldn’t initialize Builder like this if it should be there. In my opinion, I should be able to choose to do it there, especially if it works…
Code stack you are integrating Builder with
This is Next.js with SST + AWS.
Reproducible code example
I don’t have a code example but it’s pretty easy to reproduce:
- Create a Next.js Builder deployment and at least 1 Builder space.
- Move the
[[...page]].js
file into a folder called[siteId]
. - Add the code below in place of previous
getStaticPaths
andgetStaticProps
and make sure to removebuilder.init(...)
from where it was originally:
export async function getStaticPaths() {
return {
paths: [],
fallback: 'blocking',
};
}
export async function getStaticProps({ params }) {
builder.init(params.siteId); // Why does this throw and error?
const page = await builder
.get('page', {
userAttributes: {
urlPath: '/' + (params?.page?.join('/') || ''),
},
})
.toPromise();
return {
props: {
page: page || null,
},
revalidate: 5,
};
}
- Go to
localhost:3000/{yourSpacesId}/{someWebPage}
.