-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
I have a page (src/routes/things/[slug]/+page.svelte) which has a corresponding +page.server.ts file. In this file I import several images and I then use params to determine which image should be shown:
import image1 from '$lib/images/image1.png'
import image2 from '$lib/images/image2.png'
import image3 from '$lib/images/image3.png'
export const load: PageLoad = async ({ params }) => {
let imageUrl = ''
if (params.slug === 'thing1') {
imageUrl = image1
} else if (params.slug === 'thing2') {
imageUrl = image2
} else if (params.slug === 'thing3') {
imageUrl = image3
}
return {
imageUrl
}
}
A minimal example of my page is as follows:
<script lang="ts">
import type { PageData } from './$types'
export let data: PageData
</script>
<img src={data.imageUrl} alt="" />
If I log imageUrl prior to the return statement I can see that it has the expected path (e.g. /_app/immutable/assets/image1-SOME_HASH.png). But when I run vite build the assets are not present amongst the files in .svelte-kit/output/client/_app/immutable/assets. If I run vite preview and visit the page in my browser the img tag path looks correct but the image fails to load due to it not being present in the build.
When running in dev mode the images do seem to be put in the correct location so visiting the page shows the image as expected.
Also if I move the logic into +page.ts from +page.server.ts the files do get output as expected when running vite build. But unfortunately my use case requires that this logic happen on the server.
This may be me misunderstanding an intended behaviour but thought I would flag in case.
Reproduction
I hope there is enough information above to reproduce this but please let me know if not and I can add more.
Logs
No response
System Info
System:
OS: macOS 13.0
CPU: (10) arm64 Apple M1 Pro
Memory: 146.36 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.12.1 - ~/.volta/tools/image/node/18.12.1/bin/node
Yarn: 3.3.0 - ~/.volta/tools/image/yarn/3.3.0/bin/yarn
npm: 8.19.2 - ~/.volta/tools/image/npm/8.19.2/bin/npm
Browsers:
Chrome: 108.0.5359.124
Firefox: 108.0.1
Safari: 16.1
npmPackages:
@sveltejs/adapter-vercel: ^1.0.0-next.81 => 1.0.0
@sveltejs/kit: ^1.0.0 => 1.0.0
svelte: ^3.44.0 => 3.55.0
vite: ^4.0.2 => 4.0.2Severity
serious, but I can work around it
Additional Information
No response