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
Not sure if this is a SvelteKit or Vite issue, but when you attempt to fetch data from a data:application/json;... path, a CORS error is thrown in preview mode only. This is odd because the Vite config docs (https://vite.dev/config/preview-options.html#preview-cors) suggest that 'Access-Control-Allow-Origin': '*' is set in preview mode.
Error: CORS error: No 'Access-Control-Allow-Origin' header is present on the requested resource
at universal_fetch (file:///<path>/kit-cors-issue/.svelte-kit/output/server/index.js:1232:17)
The workaround is to just not ever use the preview mode, which isn't the end of the world but it's also not really a workaround.
The reproduction looks contrived, but this issue arose for me when trying to create an inline bundle for a portable SPA. The usual fetch approach doesn't work over file:// and so I swapped to import.meta.glob. Dynamically importing files that way didn't seem to play nicely with HMR, but when you fetch the globbed URLs, HMR works wonderfully. But that leads to this issue.
The text was updated successfully, but these errors were encountered:
Vite recently changed the default of server.cors due to GHSA-vg6x-rcgg-rjx6 (preview.cors defaults to server.cors). The document was not updated, it'll be fixed by vitejs/vite#19271.
On the other hand, the same error seems to happen with Vite 5.4.11 (which does not contain the server.cors change). So probably it's not caused by Vite.
Describe the bug
Not sure if this is a SvelteKit or Vite issue, but when you attempt to fetch data from a
data:application/json;...
path, a CORS error is thrown inpreview
mode only. This is odd because the Vite config docs (https://vite.dev/config/preview-options.html#preview-cors) suggest that'Access-Control-Allow-Origin': '*'
is set inpreview
mode.Reproduction
https://github.com/stephenlrandall/kit-cors-issue
In dev mode, the page loads. When deployed (https://stephenlrandall.github.io/kit-cors-issue/), the page loads. But when you build and then run
pnpm preview
, an error appears.Logs
System Info
Severity
serious, but I can work around it
Additional Information
The workaround is to just not ever use the
preview
mode, which isn't the end of the world but it's also not really a workaround.The reproduction looks contrived, but this issue arose for me when trying to create an inline bundle for a portable SPA. The usual
fetch
approach doesn't work overfile://
and so I swapped toimport.meta.glob
. Dynamically importing files that way didn't seem to play nicely with HMR, but when youfetch
the globbed URLs, HMR works wonderfully. But that leads to this issue.The text was updated successfully, but these errors were encountered: