Hi all,
I’m trying to manually generate a static html file while building a SvelteKit website. I’m using a custom Vite plugin to do so. The file is clearly being emitted in the logs, and I can download it in the deploy’s file browser. I can also access it on my local production build with Vite, but not with netlify serve
or on the web deploy. I see that it’s not in the manifest’s assets, which I assume is the issue, but I don’t know why it isn’t there or how I’m supposed to add it. I tried manually adding it to included_files
in netlify.toml
but it made no difference. I also tried writing the file using fs
rather than emitFile()
but again it didn’t work. Other static files which are present under /static
before building are accessible as normal, as well as other non-static routes.
Latest deploy
Repo
Where I emit the file
Thank you in advance!
@moiri-gamboni I’ll preface this with, I don’t work for Netlify, or with SvelteKit.
It seems the static file does exist and probably has been deployed.
As you’ve mentioned, it’s in your build log:
It also appears in the output when your build command is run locally:
However when accessed directly on Netlify a 404
is returned:
SvelteKit runs via an “adapter” on Netlify, which is mentioned in the documentation:
https://docs.netlify.com/frameworks/sveltekit/
Most of these frameworks that operate via adapter tend to generate functions that run in front of Netlify’s default handling, to provide their fancier features.
So my admittedly wild guess is that you’re leveraging that functionality, and the route is being caught and handled by that functionality instead of the default which would be delivering the static file from the CDN.
You can see that the request shows X-Sveletekit-Page
in the response headers:
I can’t advise precisely how you “fix it”, since as prefaced I don’t work with SvelteKit and the answer is likely to be either SveleteKit specific or the SveleteKit Netlify Adapater specific, but if I were you I’d investigate along that trajectory.
I’ll ask in the SvelteKit repo, hopefully they’ll have an answer. If they do I’ll report back here.
please let us know the outcome when you do!
I think I figured out what feels like a reasonable solution to this (or at least for my needs, and my searching led me here):
I put the html file in my static
directory, under a folder. So static/appropriateSubPath/index.html
and then leveraged the Netlify _redirects file with a line like the following:
/appropriateSubPath* /appropriateSubPath/index.html 200
This way Netlify does the work of serving the correct file to the user and SvelteKit doesn’t need to get involved at all.
thanks for sharing this with the Netlify community!