Netlify-internal 'Headers is not defined' error using storyblok/astro

Greetings - first items are as you request

I’ve made the site public, so you can see it. The site is essentially the demo code for storyblok/astro, and you can see it on Narration SD / Sarah SSR Storyblok · GitLab . This is a model site; original problem on a more filled-out one…

All runs fine locally, but when I build it on Netlify, there’s a hard and internal crash as you’ll see, for its small Netlify function which pulls the data. I’ve tried a number of things, including adding isomorphic-fetch just in case. But the problem, again internal to you apparenlty, seems to be missing headers for the fetch, if I had to guess.

Help, thanks!

linking image and text for the fail:

And, this is solved. I’ll put the account I gave on Discord also here – including a rather tricky thing beyond a vtricky problem to watch out for.

Here is the answer – and it is already mentioned in the note above. I’ll leave that for others to search on similar problems.

You must install isomorphic-fetch, and simply import isomorphic-fetch at the top of each page where you use storyblok-astro 's client call to pull the data. That would be because each generates its own Netlify function.

This makes excellent sense, when we are in SSR so as to be able to preview, as there’s no Node fetch then. Which makes you wonder how this ever worked for the demos described on the web, unless Astro patched for this in earlier versions, not so?

How I missed that the solution was working is that I fatally used the link on the Build log page. But that has a prefix which locks you to that build always, so you don’t see further changes! I’ve left that link alonge also, so you can see it. An interesting fact to be aware of at Netlify…

One more consideration that occurs to me is that for real life, I think we will need two Netlify sites actually with Storyblok, one to run SSR to allow previewing, and another running SSG for full performance…at least it seems so at midnight – cheers :slightly_smiling_face:

1 Like

Hi @narrationsd :wave:t6: , thanks so much and I’m super glad you were able to find your solution. This will help others experiencing similar issues. (:

Not sure if this is related but getting this same error in a deployed Netlify function on new builds starting today. There were no code changes to the function but executions of the function on all new deployments resulted in:

Invoke Error {“errorType”:“ReferenceError”,“errorMessage”:“Headers is not defined”,“stack”:[“ReferenceError: Headers is not defined”," at fromEventHeaders (file:///var/task/___netlify-bootstrap.mjs:30:19)“,” at Runtime.handler (file:///var/task/___netlify-bootstrap.mjs:318:19)“,” at Runtime.handleOnceStreaming (file:///var/runtime/index.mjs:1112:38)"]}

I have tried importing node-fetch, isomorphic-fetch, and setting the AWS lambda version to nodejs18.x with no luck… The code runs perfectly fine locally using Netlify dev and on builds prior to 2 pm pst. Any ideas?

Hi what site is being impacted?