Closed secondl1ght closed 7 months ago
It sounds like your Netlify functions are using an unsupported Node version. Try updating to 18 (here's how)
Hmm interesting, according to those docs the nvmrc
file I have in the root of my project should be defining which Node version Netlify uses. I was using lts/*
(20) when this error happened but tried changing it to 18.19.0
and the same Headers is not defined
error still happens when I visit the URL.
I use the same LTS nvmrc
file and SvelteKit for all my projects usually so I wonder why this is the only one having issues... as a workaround I changed my adapter to use adapter-static
for this site because it can actually be served as static files for this particular project.
I am still curious about solving this bug but I can close this issue if you would prefer since I have technically found a workaround. Unless you think it's worth going deeper on this?
It sounds like the nvmrc file isn't being respected, honestly — is there a place where you could log out process.versions.node
to see what's actually running?
I added console.log(process.versions.node, 'hello')
to my svelte.config.js
file and this is the output from the Netlify build logs:
It appears that it is actually using 18.19.0
from what I can tell...
Here is a link to my test branch where this is failing in production: https://github.com/secondl1ght/portfolio-v2/tree/test-node (sorry that it's not a minimal reproduction).
And here is a link to the broken branch deploy in production if you are interested in seeing that: https://test-node--secondl1ght.netlify.app/. 😅
That shows you which version of Node is building your app, but not which version is running your app — I'd expect them to be the same, but it's possible that they're not. Headers
is certainly available in 18.19, so either there's a version mismatch or there's a really weird bug in Netlify
I don't believe Netlify gives you access to the terminal that your site is running on to run log commands unfortunately... I did find this post on a forum where a user claims that the version of node used during the build in the deploy logs is the same version that runs in prod, but we can't really be sure without evidence like you say.
I am happy to close this issue now because I found a personal workaround (even though it meant not using adapter-netlify
) and I did a search on the open issues in the SK repo and I don't see any other users having the same issue as me. I am guessing there are many SvelteKit users who deploy with Netlify so if this was a common occurrence there would have been more issues opened by now.
Also I am sure you and the Svelte team have more important things to work on than this! LOL Thanks a lot for helping debug this and for all the work you guys put into developing the awesome framework that is Svelte. :)
Ran into the same issue after updating a bunch of dependencies:
ReferenceError: Headers is not defined
at to_request (file:///var/task/.netlify/functions-internal/sveltekit-render.mjs:7550:18)
at Runtime.handler (file:///var/task/.netlify/functions-internal/sveltekit-render.mjs:7523:43)
at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)
Fixed by updating the node version in the "Dependency management" section, but then also the runtime Node version:
Describe the bug
When deploying to Netlify I am receiving the following error in production:
It appears to be coming from this
to_request
function here: https://github.com/sveltejs/kit/blob/87da73e361070071b01fc459c5639d26baab34f5/packages/adapter-netlify/src/serverless.js#L62Reproduction
I have a few sites deployed with SvelteKit and Netlify but only one of them is throwing this error for some reason, even though they are all on the same versions. This is the site causing the issue: https://github.com/secondl1ght/portfolio-v2/tree/6299ee1e190ad0f7107f1721bd9686470cba4aca
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
NOTE: This happened when I upgraded to SK V2 - previously I was not getting this error in prod.
Thanks