esbuild-plugin-eslint-hybrid

raw JSON →
1.0.4 verified Fri May 01 auth: no javascript

esbuild plugin to integrate ESLint for linting code during bundling. Version 1.0.4 (latest). Supports both ESM and CJS, unlike the original esbuild-plugin-eslint which is ESM-only. Requires Node >=18.16.0, esbuild ^0.18.2, and eslint ^8.42.0 as peer dependencies. Provides filter, throwOnError, throwOnWarning, and fix options.

error TypeError: eslint is not a function
cause In CJS, not accessing .default from require.
fix
Use const eslint = require('esbuild-plugin-eslint-hybrid').default;
error Error: Cannot find module 'esbuild-plugin-eslint-hybrid'
cause Missing dependency.
fix
Run npm install esbuild-plugin-eslint-hybrid --save-dev
error Error: The plugin must be a function or an object with a 'name' property
cause Passing an undefined or incorrect plugin to esbuild.
fix
Ensure you call eslint(opts) and pass the returned object: plugins: [eslint(opts)]
gotcha In CommonJS, require returns an object; you must use .default to get the plugin function.
fix Use const eslint = require('esbuild-plugin-eslint-hybrid').default;
deprecated The original esbuild-plugin-eslint is deprecated in favor of this hybrid plugin if you need CJS support.
fix Switch to esbuild-plugin-eslint-hybrid for CJS compatibility.
gotcha The plugin does not automatically respect .eslintignore; you must configure ignores in ESLint options.
fix Pass ignorePatterns in the options object to the ESLint constructor.
npm install esbuild-plugin-eslint-hybrid
yarn add esbuild-plugin-eslint-hybrid
pnpm add esbuild-plugin-eslint-hybrid

Shows how to use the plugin with esbuild in ESM, including filter and throwOnError options.

import { build } from 'esbuild';
import eslint from 'esbuild-plugin-eslint-hybrid';

await build({
  entryPoints: ['src/app.ts'],
  outfile: 'dist/app.js',
  bundle: true,
  plugins: [
    eslint({
      filter: /\.(?:jsx?|tsx?)$/,
      throwOnError: true,
      throwOnWarning: false,
      fix: false,
    }),
  ],
});