33

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?

1
  • 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/… Commented Nov 22, 2023 at 20:39

3 Answers 3

47
  • 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.)
Sign up to request clarification or add additional context in comments.

4 Comments

The Vite dev server has to be running is the part I was missing. Thanks!
This is a great reminder to actually start your dev server first.
I think the dev server creates some files on startup, so it needs to be run only once after each relevant change.
First "npx svelte-check" if you see errors, "npx svelte-kit sync"
4

For me, just an "npm update" worked.

2 Comments

Looks like more suitable for a comment
Indeed sorry for the mistake
2

in my case typescript complaining on +page.ts when i import

import type { PageLoad } from './$types';

and then i try run

pnpm update
pnpm check 

after that type Cmd + shift + P > restart TS server or developers: Reload window (visual studio code)

by the way if you facing typescript complaining and unsure about it, you can run step above. it's worked for me as long i coded with typescript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.