Vite dev and build pass even though the Vue TypeScript code has type errors
The editor shows red type errors but npm run dev and npm run build succeedShort answer
Vite only converts TypeScript to JavaScript. It does not check types, in dev or in build, so type errors never stop it. Add a separate type check: vue-tsc for projects with .vue files, or tsc --noEmit for plain TypeScript, and run it before the build.
Fix it fast
1Find out which cause you have
Run the type checker by hand. If it prints errors that Vite did not, nothing in your pipeline is checking types.
npx vue-tsc --noEmit2Match what you see, then jump to its fix
- 1
vue-tsc --noEmit reports errors while vite build succeedsVite transpiles TypeScript and does not check itFix - 2
Errors only show up in the editor, never in the terminal or browserNo type checking while developingFix - 3
Code that the editor accepts compiles differently in the Vite buildisolatedModules is off, so unsafe syntax passes unnoticedFix
- 1
What does the error look like?
The editor shows red type errors but npm run dev and npm run build succeedA wrong prop type or wrong argument type reaches production
Cause 1 of 3
Vite transpiles TypeScript and does not check it
1Check
Read the build script. If it only calls vite build, no type check runs.
grep -n '"build"\|"dev"' package.json2Fix
Run the checker before the build, so a type error stops the script. vue-tsc is a wrapper around tsc that also reads Vue single file components.
"scripts": {
"build": "vue-tsc --noEmit && vite build"
}3Verify
Introduce a deliberate type error and run the build. It should now fail.
npm run buildConfirmed by vuejs.org
Cause 2 of 3
No type checking while developing
1Check
The dev server is transpile-only too. Vite's own docs suggest a checker running in a separate process.
npx vue-tsc --noEmit --watch2Fix
Run vue-tsc in watch mode in a second terminal next to the dev server. A plugin such as vite-plugin-checker can do the same inside Vite in a separate worker thread.
# terminal 1
npm run dev
# terminal 2
npx vue-tsc --noEmit --watch3Verify
Break a type on purpose and watch the second terminal report it.
npx vue-tsc --noEmitConfirmed by vuejs.org
Cause 3 of 3
isolatedModules is off, so unsafe syntax passes unnoticed
1Check
Vite compiles each file alone. Check tsconfig for isolatedModules.
grep -n isolatedModules tsconfig*.json2Fix
Set isolatedModules to true so TypeScript flags features that cannot work when files are compiled one by one.
{
"compilerOptions": {
"isolatedModules": true
}
}3Verify
Run the checker; it now reports code that Vite cannot compile correctly.
npx vue-tsc --noEmitConfirmed by vite.dev
How do I stop it coming back?
- Put the type check in CI so a pull request with type errors cannot merge.
- Keep vue-tsc and typescript on versions that match each other.
- Use the editor's type information while developing and the command line as the gate.
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.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
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 fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
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 fix