Keep on getting `TypeError: Found invalid object in transferList` randomly when accessing SSR pages

Name of the website:

I am not quite sure what is going on but I am randomly getting a 500 error when accessing some of my SSR pages. The problem is that this never happens on local and in production only happens from time to time. So even when I access the same page (for example this Buddha di Smeraldo: Odissea nel sud-est asiatico | The Scrapbookers), half the times it works and the other half it fails with

May 12, 07:36:18 PM: 7a700c9d ERROR  TypeError: Found invalid object in transferList     at structuredClone (/var/task/node_modules/next/dist/compiled/undici/index.js:2:7516)     at cloneBody (/var/task/node_modules/next/dist/compiled/undici/index.js:2:2108)     at cloneResponse (/var/task/node_modules/next/dist/compiled/undici/index.js:2:54244)     at Response.clone (/var/task/node_modules/next/dist/compiled/undici/index.js:2:53667)     at /var/task/.next/server/chunks/287.js:17878:22     at async getCountry (/var/task/.next/server/chunks/202.js:48:17)     at async CountryPage (/var/task/.next/server/app/[locale]/[continent]/[country]/page.js:639:26) {   code: 'ERR_INVALID_TRANSFER_OBJECT' }

The error message though is not particularly useful either as it just gives me a digest id which I have no idea on how to use.

Codebase for the repo can be found here:

I don’t think this is a Netlify issue. The error seems to be coming from undici:

However, it could be a version modified by Next.js for its own use. But, it appears that the code is trying to use structuredClone() and that object has something that cannot be cloned.

However, you’re using Node 16 in Functions, and structuredClone is not available in Node 16: Backport `structuredClone` to Node v16 · Issue #40756 · nodejs/node · GitHub. I don’t know if Node.js or any other library in your code is polly-filling it or not, but that could also be the issue. Try upgrading your Function Node.js version to Node 18.

@hrishikesh thanks so much for your reply! Upgrading my function to NodeJs 18 solved my issues indeed and the page is now loading fine! Thanks again!

Yay! Thanks for confirming you found your solution!