Skip to content
Latchkey

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.

sveltekit
[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

  1. Run a clean npm ci so all dependencies are present.
  2. Run svelte-kit sync (or npm run prepare) to generate .svelte-kit.
  3. Re-run the build.
Terminal
npm ci
npx svelte-kit sync
npm run build

Ensure prepare runs in CI

Keep the prepare script that runs sync so generated files exist before the build.

package.json
{
  "scripts": { "prepare": "svelte-kit sync" }
}

How to prevent it

  • Run npm ci so the framework package is always installed.
  • Keep a prepare script that runs svelte-kit sync.
  • Do not commit or rely on a stale .svelte-kit directory.

Frequently asked questions

What causes ""Could not resolve @sveltejs/kit""?
A skipped or partial install leaves @sveltejs/kit out of node_modules, so imports cannot resolve.
How do I fix "Could not resolve @sveltejs/kit"?
Install dependencies and run sync

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card