-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assets not output when imported in +page.server.ts #9961
Comments
It doesn't work for me too. Does anyone have a solution to this issue? |
Can you please provide a minimal reproduction in the form of a repository? |
@s3812497 Yeah, sure: https://github.com/Serator/Assets-not-output-when-imported-in-page.server.ts.
|
@Serator I can't confirm if this is a bug or intended behaviour. The assets are included in the build as server assets (which are not publicly exposed), but we want to publicly expose them (client assets). This should automatically occur for assets imported in client-side code (+page.js, +page.svelte, etc.), but does not for server code (+server.js, etc.). The only solution I know to this is to include your files in the EDIT: A hacky workaround is to just arbitrarily include it in client-side code. // routes/manifest.webmanifest/+page.js
import icon192 from './assets/icon-192.png';
import icon512 from './assets/icon-512.png'; Perhaps we need an option to include server assets as client assets similar to vite-plugin-ssr? https://vite-plugin-ssr.com/includeAssetsImportedByServer |
That's exactly what I did, but in the long run I'd like to be able to add assets without this trick. |
This looks like a hack and it's going to be hard to figure out what's going on here, even though that's what works. |
The solution might best be provided by Vite and so I've provided feedback here vitejs/vite#13808 EDIT: we may have to implement it in Kit itself as suggested here vitejs/vite#13808 (reply in thread) |
@Serator @liegeandlief I've made a mistake in identifying the issue. As pointed out by vitejs/vite#13808 (reply in thread) SvelteKit always copies server assets to be available client-side (public). The only instance where the assets are not being exposed publicly is when As long as you specify the adapter or prod environment, this shouldn't be an issue. |
@s3812497 What do you mean by |
e.g., If you see this warning after building your app with > Using @sveltejs/adapter-auto
Could not detect a supported production environment. See https://kit.svelte.dev/docs/adapters to learn how to configure your app to run on the platform of your choosing |
@s3812497 I explicitly set |
Is it still an issue when deployed to Vercel or just when previewing with |
@s3812497 I've just tested this for the first time in a while (with all dependencies up to date) and it seems to be working now when running preview and build 🎉 |
@s3812497, @liegeandlief I tried building the project and running in preview mode, but it still doesn't work for me either with " |
Sorry, I just discovered preview mode will not work for any adapter but the build output should be fine when deploying. I have a fix in the works that should make preview mode copy over the right server assets. |
@s3812497 Now it's working for me. Thank you! |
Describe the bug
I previously raised this bug - #8224
It was closed because it was a duplicate of #5240 which has been closed as resolved by #9073
But this is still an issue for me. The problem doesn't occur when running the dev server only when running
vite build
andvite preview
. I am using theIs there something I need to do to get this to work?
Reproduction
See #8224
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: