Vite ESLint Plugin

raw JSON →
1.9.2 verified Mon Apr 27 auth: no javascript

An ESLint plugin for Vite that lints JavaScript, TypeScript, Vue, and Svelte files during development and build. Version 1.9.2 is the current stable release, with no major release cadence documented. It is a fork of vite-plugin-eslint, offering additional configuration options such as lintOnStart, custom eslintPath, and granular failOnWarning/failOnError settings. Key differentiators include better control over linting behavior and support for modern file types.

error TypeError: eslint is not a function
cause Using named import `{ eslint }` instead of default import.
fix
Change import to: import eslint from 'vite-eslint-plugin'
error Error: ESLint configuration is invalid: No configuration found for file...
cause ESLint cannot find an ESLint configuration file (e.g., .eslintrc) in the project root.
fix
Create an ESLint configuration file (e.g., .eslintrc.json) or specify overrideConfigFile in plugin options.
error Error: Cannot find module 'eslint'
cause ESLint is not installed as a peer dependency.
fix
Install eslint: npm install eslint --save-dev
gotcha The plugin may significantly slow down HMR if lintOnStart is enabled, because it lints all matching files on startup.
fix Set lintOnStart: false (default) unless you need initial linting of the whole project.
breaking Version 1.0.0 changed the export from a named object to a default function. Existing code using `import { eslint } from 'vite-eslint-plugin'` will break.
fix Use default import: `import eslint from 'vite-eslint-plugin'`.
deprecated The option `emitWarning` and `emitError` are deprecated in favor of `failOnWarning` and `failOnError`.
fix Use `failOnWarning` and `failOnError` instead.
gotcha If you use TypeScript and have `@types/eslint` installed, you may need to ensure the versions align with your eslint peer dependency.
fix Align @types/eslint version with eslint peer dependency (>=7).
npm install vite-eslint-plugin
yarn add vite-eslint-plugin
pnpm add vite-eslint-plugin

Configures the ESLint plugin for production builds (fails on errors) and development server (warnings and errors do not fail).

// vite.config.ts
import { defineConfig } from 'vite'
import eslint from 'vite-eslint-plugin'

export default defineConfig({
  plugins: [
    {
      // fail on errors during build
      ...eslint(),
      apply: 'build',
    },
    {
      // do not fail during dev
      ...eslint({ failOnWarning: false, failOnError: false }),
      apply: 'serve',
      enforce: 'post',
    },
  ],
})