SvelteKit, import type LayoutServerLoad/PageLoad
Asked Answered
H

2

28

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?

Hirohito answered 13/10, 2022 at 18:20 Comment(1)
You don't need to import these types any more if you're using VS Code with the latest version of the Svelte for VS Code extension installed (or one of other specific set-ups mentioned on the page linked to), and in fact removing them is what fixed this problem for me. svelte.dev/blog/…Crouton
I
36
  • 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
  • (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.)
Iodism answered 13/10, 2022 at 18:54 Comment(2)
The Vite dev server has to be running is the part I was missing. Thanks!Isolationist
This is a great reminder to actually start your dev server first.Fridge
B
3

For me, just an "npm update" worked.

Balzac answered 4/4, 2023 at 15:40 Comment(2)
Looks like more suitable for a commentPedi
Indeed sorry for the mistakeBalzac

© 2022 - 2024 — McMap. All rights reserved.