Vite build passes locally but fails on Vercel with a vite/client type error
Cannot find type definition file for 'vite/client'Short answer
The vite/client types ship inside the vite package. If the Vercel build did not install vite, TypeScript cannot resolve them, even though your local machine can. Check the Install Command and Root Directory first, then confirm tsconfig lists vite/client or a vite-env.d.ts file references it.
Fix it fast
1Find out which cause you have
Run a clean install and the build the way Vercel does, then check that vite is present in node_modules before the build starts.
rm -rf node_modules npm ci ls node_modules/vite/client.d.ts npm run build2Match what you see, then jump to its fix
- 1
The install log shows production-only installs and node_modules/vite does not existThe Install Command skips devDependencies, so vite is missingFix - 2
Your repository has the app in a subfolder, and the root package.json has no viteVercel installs from a different folder than the one that holds viteFix - 3
The error appears in your own tsc run too, after removing node_modulestsconfig lists vite/client in types but nothing declares itFix
- 1
What does the error look like?
Cannot find type definition file for 'vite/client'Error: Command "npm run build" exited with 1
Cause 1 of 3
The Install Command skips devDependencies, so vite is missing
1Check
Vite is normally a devDependency. Vercel installs devDependencies by default, but a custom Install Command such as npm install --only=production or yarn install --production leaves them out.
grep -n "installCommand" vercel.json
grep -n '"vite"' package.json2Fix
Remove the production-only Install Command in Project Settings or vercel.json, or move vite to dependencies.
# in the Vercel dashboard, Build and Deployment: turn the Install Command override off
# or install everything
npm install3Verify
Redeploy. The build log gets past the tsc step.
npx vercel --prodConfirmed by vercel.com
Cause 2 of 3
Vercel installs from a different folder than the one that holds vite
1Check
The install path comes from the project's Root Directory. If Root Directory is empty, Vercel installs from the repository root, where vite is not listed.
ls package.json
ls */package.json2Fix
Set Root Directory in Project Settings to the folder that contains the Vite app and its package.json, then redeploy.
# Project Settings -> Build and Deployment -> Root Directory
apps/web3Verify
The install step now runs in that folder and node_modules/vite exists during the build.
npx vercel --prodConfirmed by vercel.com
Cause 3 of 3
tsconfig lists vite/client in types but nothing declares it
1Check
Vite documents two ways to load its client types: add vite/client to compilerOptions.types, or add a d.ts file with a reference line. Check which one you rely on.
grep -n "vite/client" tsconfig*.json src/*.d.ts2Fix
Use one of the two documented forms. With the declaration file, make sure tsconfig include covers it.
// src/vite-env.d.ts
/// <reference types="vite/client" />3Verify
Run the type check without emitting files.
npx tsc --noEmitConfirmed by vite.dev
How do I stop it coming back?
- Keep the Install Command on Vercel at its default unless you have a reason.
- Commit the lockfile so the same vite version installs everywhere.
- Run npm ci and the build from a clean checkout before you deploy.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
Vercel says npm run build exited with 1 and my deployment fails
Error: Command "yarn run build" exited with 1
Exited with 1 only says the build script failed.
4 causes, each with a fixWeb apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
Cypress refuses to start with 'Your configFile is invalid'
Your configFile threw an error from: /path/to/cypress.config.ts
Cypress could not load cypress.config.js or .ts, or found something wrong in it.
5 causes, each with a fixWeb apps
ESLint cannot decide which copy of the @typescript-eslint plugin to use
The message lists two file paths for the same plugin, each with the name of the config that loaded it
ESLint found the same plugin at two different file paths and will not pick one.
3 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint was configured to run using parserOptions.project, but the file is not in the TSConfig
However, that TSConfig does not include this file
Type-aware linting needs every linted file to belong to a TypeScript project.
4 causes, each with a fix