You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the documentation (here and here), kits fetch should be able to handle relative paths on the server.
This works in development, but not in production (I've tested Cloudflare and node adapters).
If I do this:
// +server.tsimportassetfrom"$lib/image.png";exportconstGET=async({fetch: sk_fetch})=>{const_asset=awaitsk_fetch(asset);// we always end up hereif(!_asset.ok)returnerror(404,"Not found");return_asset;};
The response is always this exact 404 (as far as I can tell):
this isn't optimal because for each asset a whole request is needed (performance cost)
and one has to construct the absolute URL from vites asset import
Semantically async read + Cloudflare implementation, would be most satisfying, but it's probably leas viable, because of breaking change.
But independent of read, not being able to fetch assets using relative path on server seams to be a bug, that should be fixed (or if not at least a warning in dev mode would be nice).
Describe the bug
According to the documentation (here and here), kits
fetch
should be able to handle relative paths on the server.This works in development, but not in production (I've tested Cloudflare and node adapters).
If I do this:
The response is always this exact 404 (as far as I can tell):
kit/packages/kit/src/runtime/server/respond.js
Lines 118 to 120 in df6641a
We end up here, because the
server_fetch
doesn't recognise this path as an asset.Following check seams to be the problem:
kit/packages/kit/src/runtime/server/fetch.js
Lines 84 to 87 in df6641a
as it doesn't check
manifest._.server_assets
I've created an exhaustive reproduction that shows differences between sk/global fetch and absolute/relative path here:
https://github.com/mastermakrela/sveltekit-relative-assets-fetch-bug
Solutions considered
Use
read
read
is sync and Cloudflaresenv.ASSETS.fetch
isn'tChange
is_asset
check in Kit toChange
is_static_asset
check in Cloudflare adapter to:Use global fetch
Semantically async
read
+ Cloudflare implementation, would be most satisfying, but it's probably leas viable, because of breaking change.But independent of read, not being able to fetch assets using relative path on server seams to be a bug, that should be fixed (or if not at least a warning in dev mode would be nice).
Reproduction
https://github.com/mastermakrela/sveltekit-relative-assets-fetch-bug
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: