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.
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
- Run a full install (do not pass
--omit=dev) in the build job. - Confirm
NODE_ENVis notproductionduring install. - Run the build from the same directory the install populated.
- run: npm ci
- run: npm run buildInstall in the correct workspace
For a monorepo, install at the root or target the app workspace so the package lands where the build runs.
npm ci --workspaces
npm run build --workspace apps/webHow 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=productionbefore the build step.