Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SvelteKit, import type LayoutServerLoad/PageLoad

Tags:

sveltekit

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 'LayoutServerData'?

What do I need to do to get the type LayoutServerLoad (or PageLoad or PageServerLoad ...) in ./$types?

like image 574
Nausika Avatar asked Sep 03 '25 09:09

Nausika


2 Answers

  • The file has to be called +layout.server.ts (or for another load action, one of the other fixed names, see docs)
  • The Vite dev server has to be running, which watches the files and generates the types when a file is changed. (You can also execute svelte-kit sync to generate those files.)
  • (The tsconfig.json has to extend .svelte-kit\tsconfig.json, which defines rootDirs, so the generated types are resolved. This should already be the case, judging by the suggestion for LayoutServerData.)
like image 186
H.B. Avatar answered Sep 05 '25 01:09

H.B.


For me, just an "npm update" worked.

like image 26
Maxime Curon Avatar answered Sep 05 '25 01:09

Maxime Curon