3,012 questions
62
votes
4
answers
146k
views
npm run dev --host network: not exposed
I want to expose my svelte app on LAN using the npm run dev --host command but it shows:
> [email protected] dev
> svelte-kit dev
SvelteKit v1.0.0-next.295
local: http://localhost:3000
...
46
votes
5
answers
59k
views
Where to put images with SvelteKit
I have been using Svelte for a little while and now I have switched to SvelteKit so I can add multiple pages. I want to add some images to my site but I don't know where to put them. In Svelte I would ...
40
votes
5
answers
59k
views
SvelteKit: how do I do slug-based dynamic routing?
I am a newbie on Svelte and in coding in general. I'd prefer to learn SvelteKit (Svelte@Next) rather than sapper since that seems to be where Svelte is heading.
For my personal project, I need to ...
33
votes
3
answers
17k
views
SvelteKit, import type LayoutServerLoad/PageLoad
In layout.server.ts I try to
import type { LayoutServerLoad } from './$types';
but the type can't be found:
'"./$types"' has no exported member named 'LayoutServerLoad'. Did you mean '...
31
votes
5
answers
17k
views
Sveltekit + Typescript: Environment variables build error
I want to use environment variables in my Sveltekit app - it works fine on dev server, but I get this build error:
Error: 'PUBLIC_KEY' is not exported by $env/static/public, imported by src/routes/+...
31
votes
4
answers
32k
views
cannot find package sveltejs/adapter-auto svelte.config.js
I am new to SvelteKit and have built an initial project from the SvelteKit docs. When the project opens I receive the following error when looking at index.svelte.
Error in svelte.config.js
Error [...
28
votes
3
answers
79k
views
How to redirect to page in SvelteKit?
I have a page with content rendered from a SvelteKit store. If the store is invalid, a user needs do be redirected to the homepage. Unfortunately, I can't find a way to redirect a user even without ...
26
votes
2
answers
9k
views
SvelteKit: How to output build as single HTML file with inlined JS and CSS?
Is it possible to build a SvelteKit project to a single output HTML file which inlines all JS and CSS? Could SvelteKit be configured to support this output format or do I need to use an external build ...
23
votes
1
answer
12k
views
How to extend Locals interface in SvelteKit
The Svelte documentation shows how to set an element on locals in hooks: https://kit.svelte.dev/docs/hooks#server-hooks
event.locals.user = await getUserInformation(event.cookies.get('sessionid'));
...
22
votes
1
answer
11k
views
Drizzle Studio : There is not enough information to infer relation
I'm trying to launch drizzle studio but I get the following error :
Error: There is not enough information to infer relation "restaurantsTable.categories"
What have I done wrong ?
schema.ts
...
21
votes
2
answers
17k
views
How can I tell whether SvelteKit's "load" function is running on the server vs. client?
I'm trying to do API calls in a SvelteKit page from the load function, but I don't want to proxy these calls with local endpoints because I want to keep the web server as light as possible.
What I ...
18
votes
5
answers
26k
views
Going back to the previous page with 'goto' / Sveltekit navigation
I normally use the following to redirect to any page without using window.location.href in Sveltekit
import { goto } from '$app/navigation';
const goSomeWhere = () :void => {
goto('/')
}
But ...
18
votes
1
answer
18k
views
How do I disable minification when running "build" command in sveltekit?
I am deploying sveltekit to a dfinity container and I need to disable minification to debug.
I have to build a static version to deploy it with npm run build -- is there a vite option to disable ...
17
votes
3
answers
19k
views
Building svelte app as a set of static files
I want to use Svelte in my next project, due to its clean syntax and how nice is to work in it. Unfortunately, to deploy the app in my company I can't use node or anything like that on the server. I ...
16
votes
7
answers
31k
views
Tailwind and Vite warnings: "didn't resolve at build time, it will remain unchanged to be resolved at runtime"
I'm using the following combination of technologies:
SvelteKit (1.5.0, using TypeScript), with Vite (4.0.0) as the build tool that comes with SvelteKit)
Svelte's adapter-static (2.0.1) for publishing ...
16
votes
1
answer
8k
views
Setup SSG and Prerender in SvelteKit
I just got started with SvelteKit and read the documentation. I would like to use SSG in my app and prerender every page. I configured my app as the documentation said but nothing seems to work as ...
15
votes
3
answers
15k
views
SvelteKit console error "window is not defined" when i import library
I would like to import apexChart library which using "window" property, and i get error in console.
[vite] Error when evaluating SSR module /src/routes/prehled.svelte:
ReferenceError: window ...
14
votes
2
answers
18k
views
Svelte components with generics
I want to use a generic type in a Svelte(Kit) component's props, and I found out there is this type T = $$Generic thing:
<script lang="ts">
import type { Writable } from "svelte/...
14
votes
1
answer
6k
views
How do we do "named slots" in in Svelte 5?
Svelte 5 Slots are Confusing
Now, with Svelte 5 at pre-release, I feel I can express some confusion about slots in Svelte 5. In Svelte 4, slot and names slots where done in the following way:
...
14
votes
1
answer
12k
views
Your page did not fire its `load` event within `60000ms` only on Github Actions
I have Cypress tests failing only on Github CI with this error:
Your page did not fire its `load` event within `60000ms`.
I assume this is because the Cypress browser is stuck loading something ...
13
votes
3
answers
7k
views
How do I add a version number to a SvelteKit/Vite app?
I'm trying to create a system in my SvelteKit app where it shows you info about the current app version (ideally a Git commit hash and description) on a certain page. I tried using Vite's define ...
13
votes
2
answers
12k
views
SvelteKit - load() not called from component but works as a Page
If the file test.svelte below is a Page in /routes, it successfully calls load() and populates the template with the JSON array it retrieves when I access it via http://localhost:3000/test. If I move ...
13
votes
1
answer
11k
views
How to Import Types in SvelteKit - PageLoad / PageServerLoad
I'm trying to import the PageLoad function for the SvelteKit load function according to the docs.
The import does not seem to exist. This is a brand new app with the latest version of SvelteKit. It ...
12
votes
6
answers
16k
views
Sveltekit: Styling active links with $page.path
I'm working on a sveltekit app with a sidenav containing links. I can't get the active class styling on my links to work properly.
The links are components in NavLink.svelte:
<script>
import { ...
12
votes
2
answers
13k
views
SvelteKit - How to make SCSS variables/mixins globally available to all components?
In Nuxt, I use the Style Resources package to make SCSS available globally and I can access variables and mixins in any component. How to do the same in SvelteKit?