Maaz Zindani

Loading the index…

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

Vite dev and build pass even though the Vue TypeScript code has type errors

ErrorThe editor shows red type errors but npm run dev and npm run build succeed

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

  • Applies to Vite 7, Vue 3, vue-tsc 3, TypeScript 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

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

    1. 1vue-tsc --noEmit reports errors while vite build succeedsVite transpiles TypeScript and does not check itFix
    2. 2Errors only show up in the editor, never in the terminal or browserNo type checking while developingFix
    3. 3Code that the editor accepts compiles differently in the Vite buildisolatedModules is off, so unsafe syntax passes unnoticedFix

What does the error look like?

  • The editor shows red type errors but npm run dev and npm run build succeed
  • A 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.json

2Fix

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 build

Confirmed by vuejs.org

Did this fix it?

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

2Fix

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

3Verify

Break a type on purpose and watch the second terminal report it.

npx vue-tsc --noEmit

Confirmed by vuejs.org

Did this fix it?

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

2Fix

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

Confirmed by vite.dev

Did this fix it?

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:

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.