Vite

Running TypeScript and ESLint checks alongside Vite

Use vite-plugin-checker to run TypeScript and ESLint diagnostics in a worker, tune the browser overlay, and keep production CI checks explicit.

Running TypeScript and ESLint checks alongside Vite

Vite can serve code with a type error because transforming TypeScript and checking its types are different jobs. I use vite-plugin-checker for feedback while the dev server runs, and keep explicit type and lint commands for CI.

See what a successful Vite transform actually proves

In the esbuild-based Vite setup shown here, the transform removes type syntax and emits JavaScript. The reported 20–30x comparison with tsc is workload dependent, and the tools are doing different work in that comparison. The speed comes from avoiding full-project semantic analysis on each transform.

1
2
3
4
5
6
7
8
9
10
11
12
13
// src/components/UserProfile.tsx
interface UserProps {
  userId: string;
  userAge: number; // Expects a number
}

export function UserProfile(props: UserProps) {
  return <div>{props.userId} ({props.userAge})</div>;
}

// Incorrect use from another file
<UserProfile userId="namju" userAge="thirty-two" /> 
// -> Transpilation can emit this even with a type error.

The caller passes a string where the component expects a number. The browser runs the emitted JavaScript. Even a successful vite build does not replace tsc --noEmit or a tool that checks the framework’s type system. I keep the error in a small test component when verifying the checker’s configuration so I can tell a misconfigured checker from a clean project.

Put diagnostics on a separate path from HMR

flowchart TD
    subgraph MainThread["Main thread (Vite dev server)"]
        Req["Browser request"] --> Esbuild["esbuild transpilation"]
        Esbuild --> FastHMR["HMR update"]
        FastHMR --> ClientWS["@vite/client WebSocket"]
    end
    subgraph WorkerThread["Background worker"]
        FileChange["File change"] --> CheckerEngine["vite-plugin-checker"]
        CheckerEngine --> TsWorker["Worker 1: tsc --noEmit"]
        CheckerEngine --> EslintWorker["Worker 2: ESLint Linter"]
        TsWorker --> DiagnosticAggregator["Collect diagnostics"]
        EslintWorker --> DiagnosticAggregator
    end
    FileChange -.-> Req
    DiagnosticAggregator -->|"Report errors"| OverlayHub["Browser overlay and terminal"]
    OverlayHub --> ClientWS

vite-plugin-checker uses a worker during development, so serving a changed module does not need to wait for the full diagnostic cycle. The checker can report issues to the terminal and show them in the browser overlay. The work still competes for CPU and memory, which can show up on a small machine or in a large watch graph.

The architectural distinction matters when investigating latency. If editing triggers a slow browser refresh, inspect the dev server and transform path. If the UI changes quickly but a diagnostic arrives late, inspect the checker’s first project scan, watcher scope, and reported TypeScript project.

Configure which project and files to check

1
pnpm add -D vite-plugin-checker typescript eslint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// vite.config.ts
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';

export default defineConfig({
  plugins: [
    checker({
      // 1. Enable TypeScript checking
      typescript: true, // or { tsconfigPath: './tsconfig.app.json' }

      // 2. Enable ESLint flat configuration
      eslint: {
        useFlatConfig: true,
        lintCommand: 'eslint "./src/**/*.{ts,tsx}"'
      },

      // 3. Configure the browser overlay
      overlay: {
        initialIsOpen: false, // Keep the overlay collapsed on load
        position: 'tr',       // Show it in the top-right corner
        badge: true           // Show a compact error count
      },

      // 4. Control terminal output
      terminal: true,

      // 5. Framework option for Vue projects
      // vueTsc: true,
      
      // 6. Option when using Biome
      // biome: true
    })
  ]
});

For TypeScript, typescript: true checks the default project. A repository with separate application and test configurations can point at its application tsconfig. ESLint should lint the source set the team actively edits. When using flat config, put ignores such as build output in eslint.config.js and confirm the lint command targets the same patterns in development and CI.

I set initialIsOpen: false and leave the badge enabled. The browser then shows that an error exists without consistently covering the layout I need to inspect. The terminal should still display enough context to find the failing file and line.

Decide how the production command fails

1
2
3
4
5
6
7
8
9
// vite.config.ts
export default defineConfig({
  plugins: [
    checker({
      typescript: true,
      enableBuild: true // Run diagnostics during the production build
    })
  ]
});

A repository can enable checks as part of the Vite build. For a larger pipeline I also define explicit commands so the job output distinguishes type, lint, and bundler failures. Separate jobs use their caches independently and can run in parallel. With that setup, I avoid checking the same project twice on a constrained worker.

1
2
3
4
5
6
7
8
9
// package.json
{
  "scripts": {
    "dev": "vite",
    "type-check": "tsc --noEmit",
    "lint": "eslint .",
    "build": "tsc --noEmit && vite build"
  }
}

A failing command must affect CI status. It is easy to miss that if the pipeline logs diagnostics then continues after a nonzero exit. I test the failure path once with an intentional type error before relying on the gate.

Verify the worker and the build

Terminal showing a TS2322 diagnostic reported by the checker worker Figure 1. The dev server is ready in 154 ms in this example, and the worker separately reports that the string prop conflicts with a number.

After fixing the caller to pass userAge={32}, run the build and confirm the enabled type and lint checks complete without errors.

Vite build terminal with zero TypeScript and ESLint errors after correcting the prop Figure 2. The corrected prop passes the checks and lets the production bundle complete.

Keep feedback useful as a repository grows

  • Use an application tsconfig when tests, stories, or generated code are irrelevant to the development overlay.
  • Keep lint scope aligned with the CLI and exclude generated files at the configuration level.
  • Treat the worker as a feedback mechanism and CI as the quality gate, even if both run the same commands.
  • If the development server feels slow before any diagnostics arrive, inspect initial module transformation separately.
This post is licensed under CC BY 4.0 by the author.