SvelteKit "Could not resolve @sveltejs/kit" build error in CI
The build cannot resolve @sveltejs/kit or its generated types in .svelte-kit. Either the package was not installed by the clean CI install, or svelte-kit sync never ran to produce the generated files.
What this error means
vite build / svelte-kit build fails with "Could not resolve \"@sveltejs/kit\"" or "Cannot find module './$types'" referencing the generated .svelte-kit directory.
[vite]: Rollup failed to resolve import "@sveltejs/kit" from "src/hooks.server.js".
Cannot find module './$types' or its corresponding type declarations.Common causes
Dependencies were not installed cleanly
A skipped or partial install leaves @sveltejs/kit out of node_modules, so imports cannot resolve.
svelte-kit sync did not run
The generated .svelte-kit directory (including $types) is produced by svelte-kit sync; without it, generated imports are missing.
How to fix it
Install dependencies and run sync
- Run a clean
npm ciso all dependencies are present. - Run
svelte-kit sync(ornpm run prepare) to generate.svelte-kit. - Re-run the build.
npm ci
npx svelte-kit sync
npm run buildEnsure prepare runs in CI
Keep the prepare script that runs sync so generated files exist before the build.
{
"scripts": { "prepare": "svelte-kit sync" }
}How to prevent it
- Run
npm ciso the framework package is always installed. - Keep a
preparescript that runssvelte-kit sync. - Do not commit or rely on a stale
.svelte-kitdirectory.