Home
Support Forums

Unusual build failures with Next.js

I have a site agitated-goldstine-6a8d97 that is a simple Next.js demo. The site was building locally and even via netlify build locally but when deployed it gave the following error:

2:11:33 PM: Unhandled error during request: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "authorization"

This seemed similar to an error I’d run into locally that was only fixed by deleting the .next folder with the cache. I tried multiple times to clear cache and deploy on Netlify but with the same result. Realizing that the site built locally, I tried using netlify deploy and that worked, deploying a deploy preview. So I ran netlify deploy --prod and that also worked, building the site for production.

The key thing is, this is the exact same code that works but also failed to build. It almost seems like the cache for Next is not getting blown away completely or something, but that’s just a guess.

Hi @remotesynth

What is the error relating to? Is data fetched during build that requires authorisation? Where is the value (e.g. auth key) coming from? An environment variable? I might consider the value wasn’t read so got passed as undefined.

@coelmay The only API that I connect to is the LaunchDarkly API. However, I was connecting to that API just fine in prior builds. I continue to see the build fail if I just check in via GitHub but the build succeed using netlify build and to deploy successfully using netlify deploy --prod. Not sure why they would be different.

The other weird part is that the LaunchDarkly API is called on every page but the error only shows the failure on the about.js page.

Figured this one out and it was a mistake on my end. I had the wrong name for the environment variable on Netlify. The local build test using netlify build and the local netlify deploy used the correct variable name that is in the .env.local file but the Neltify build was using the incorrect name I had suppled in the admin console

1 Like

Hey there, @remotesynth :wave:

Thank you so much for coming back and updating this thread with our solution! This will be helpful for any future Forums members who encounter something similar. :netliconfetti: