Skip to content
Latchkey

Svelte "Cannot find module '@sveltejs/kit'" import in CI

Node tried to resolve @sveltejs/kit and found nothing in node_modules. In CI this almost always means the package was not installed, usually because dev dependencies were pruned or the install ran in the wrong directory.

What this error means

A vite build or svelte-kit sync step throws "Error: Cannot find module '@sveltejs/kit'" even though the app builds locally where dependencies are already present.

node
Error: Cannot find module '@sveltejs/kit'
Require stack:
- /home/runner/work/app/app/svelte.config.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)

Common causes

Dev dependencies were skipped during install

@sveltejs/kit is a devDependency. An install with --omit=dev or NODE_ENV=production prunes it, so the build cannot resolve it.

The install ran in a different directory than the build

In a monorepo the install populated one workspace while the build runs in another, leaving that package without its node_modules.

How to fix it

Install dev dependencies before building

  1. Run a full install (do not pass --omit=dev) in the build job.
  2. Confirm NODE_ENV is not production during install.
  3. Run the build from the same directory the install populated.
.github/workflows/ci.yml
- run: npm ci
- run: npm run build

Install in the correct workspace

For a monorepo, install at the root or target the app workspace so the package lands where the build runs.

Terminal
npm ci --workspaces
npm run build --workspace apps/web

How to prevent it

  • Keep npm ci (full install) in the build job, not a production-only install.
  • Run install and build from the same working directory.
  • Avoid setting NODE_ENV=production before the build step.

Frequently asked questions

What causes ""Cannot find module '@sveltejs/kit'""?
@sveltejs/kit is a devDependency. An install with --omit=dev or NODE_ENV=production prunes it, so the build cannot resolve it.
How do I fix "Cannot find module '@sveltejs/kit'"?
Install dev dependencies before building

Related guides

References

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