Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite build passes locally but fails on Vercel with a vite/client type error

ErrorCannot 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.

  • Applies to Vite 6, Vite 7, TypeScript 5, Node.js 22, Vercel
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 build
  2. 2Match what you see, then jump to its fix

    1. 1The install log shows production-only installs and node_modules/vite does not existThe Install Command skips devDependencies, so vite is missingFix
    2. 2Your 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. 3The error appears in your own tsc run too, after removing node_modulestsconfig lists vite/client in types but nothing declares itFix

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.json

2Fix

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 install

3Verify

Redeploy. The build log gets past the tsc step.

npx vercel --prod

Confirmed by vercel.com

Did this fix it?

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.json

2Fix

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/web

3Verify

The install step now runs in that folder and node_modules/vite exists during the build.

npx vercel --prod

Confirmed by vercel.com

Did this fix it?

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.ts

2Fix

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 --noEmit

Confirmed by vite.dev

Did this fix it?

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:

Related fixes

Web 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.