vite-plugin-eslint2

raw JSON →
5.1.0 verified Sat Apr 25 auth: no javascript

ESLint plugin for Vite that integrates ESLint linting into the Vite dev server and build process. Current stable version is v5.1.0, released December 2024. Releases are frequent, approximately monthly. Key differentiators: supports a wide range of Vite versions (v2–v8) and ESLint versions (v7–v10), works as a standard Vite plugin, uses worker threads for performance, and includes TypeScript definitions. Unlike alternatives like vite-plugin-eslint (deprecated) or eslint-webpack-plugin, this plugin is specifically designed for Vite's architecture and actively maintained.

error ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './eslint' is not defined by "exports"
cause Using an outdated import like `import eslint from 'vite-plugin-eslint2/eslint'` (assuming a subpath export).
fix
Use import eslint from 'vite-plugin-eslint2' instead.
error Cannot find module 'eslint/use-at-your-own-risk'
cause Trying to use a deprecated internal ESLint API (e.g., `ESLint` class from `use-at-your-own-risk`).
fix
Use import { ESLint } from 'eslint' and pass it as a factory function in plugin options.
error TypeError: eslint is not a function
cause Importing the module as a named export (`import { eslint } from 'vite-plugin-eslint2'`) instead of default.
fix
Use import eslint from 'vite-plugin-eslint2' (default import).
breaking In v5.0.0, the `chokidar` option was removed. If you were relying on it for file watching, you must use Vite's built-in file watching instead.
fix Remove the `chokidar` option from plugin options.
breaking ESLint v9+ uses flat config by default. If you upgrade from v8 to v9, your `.eslintrc` config might not work; you need to migrate to `eslint.config.js`.
fix Create an `eslint.config.js` file with flat config, or set `ESLINT_USE_FLAT_CONFIG=false` temporarily.
deprecated ESLint v7 and v8 are deprecated. The plugin still supports them but they are not receiving updates.
fix Upgrade to ESLint v9 or later.
gotcha The plugin uses a worker thread for linting. If you use a custom `eslint` instance that is not serializable, the worker might fail.
fix Ensure the `eslint` option passed to the plugin is a function that returns a new instance, not an already-created instance.
npm install vite-plugin-eslint2
yarn add vite-plugin-eslint2
pnpm add vite-plugin-eslint2

Basic setup of vite-plugin-eslint2 in a Vite config with common options.

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

export default defineConfig({
  plugins: [
    eslint({
      exclude: ['node_modules', 'dist'],
      lintOnStart: true,
      cache: true
    })
  ]
});