Closed tseppl closed 4 months ago
We do not modify the fetch cache entry, so if the JSON is incorrect the issue is coming from next itself.
It might not appear as an issue in next because if it throws an exception while loading this cache item, it will consider that the item is not cached and refetch.
We could add a try catch
block around the JSON.parse()
during build to catch this error, but it won't solve the underlying issue.
Could you try with next@14.1
and open-next@2.3.5
?
This looks like an error at build time, can you log the json
data of the fetch request on the page?
After adding try/catch blocks around different parts of the application it seems that the page was not able to render because of https://nextjs.org/docs/messages/dynamic-server-error and will produce this error also during "npm run build", so the error is not open-next related.
We are also experiencing the same issue, triggering another build works most of the time. In our case we are getting an extra curly bracket at the end. Will also try and see if this is caused by some other issue first.
@tseppl I also added some try catch blocks but it's not logging anything. Bundling cache assets
only start after successfully generating static pages so I wonder where you added your try catch statements. Note that I am not getting any error when running the regular next build (non open-next) locally.
@Jdruwe
For me "npm run build" would not produce any errors before adding the try catch blocks and this was ultimately also the reason why I thought it was an issue with open-next. After adding try catch blocks around fetch json parse the build would finally fail with Dynamic Server Error.
I think Dynamic Server Error usually originates from trying to render the page statically but using dynamic resources such as headers, cookies, searchparams etc which are only available during client runtime.
@tseppl Thanks for the response,
I have to admit I cannot remember all the details anymore but try adding a try catch block around where you fetch data inside your components. Also if you try to access things like cookies etc. This way you will at least get an error displayed.
try {
const response = await fetch('https://website');
} catch (error) {
// TypeError: Failed to fetch
console.log('There was an error', error);
}
I think there is some problems with consistency with this setup. So sometimes you have to delete the .next dir manually and then run build again. Some cache won't clear itself for some reason at times. To get a consistent result you can write a script that first deletes the .next dir and then starts the build.
I am trying to deploy a NextJs site, which works locally when running "npm run dev" and also build succeeds by running "npm run build", but fails when running "npx sst deploy".
It seems there are a few extra characters in the end of the JSON - specifically ]}
Here is the excerpt from terminal (some info obfuscated or stripped):