eslint-config-vitest-globals

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

ESLint configuration package that defines globals for Vitest test files, eliminating false no-undef errors for Vitest globals like vi, describe, it, expect, beforeEach, etc. Version 2.0.2 is current, with support for both ESLint v9 flat config and ESLint v8 traditional config. Ships TypeScript types. Differentiators: tiny focused package, no extra rules, just globals; explicit flat config path import for ESLint v9; actively maintained with recent updates.

error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'eslint-config-vitest-globals/flat'
cause Using flat config import but package version is <2.0.0 (old version) or import path is wrong.
fix
Update package to v2.0.0+ and ensure import path is 'eslint-config-vitest-globals/flat'.
error ESLint: TypeError: vitestGlobals is not a function
cause Importing default from 'eslint-config-vitest-globals/flat' but not calling it (using as object instead of function).
fix
Use vitestGlobals() in your config array.
error Parsing error: The keyword 'import' is reserved
cause Using 'import' in a CommonJS file without ESM support.
fix
Change file extension to .mjs or set "type": "module" in package.json, or use require() if available.
breaking v2.0.0 changed export structure: flat config must be imported from subpath 'eslint-config-vitest-globals/flat' instead of default import.
fix Update import path from 'eslint-config-vitest-globals' to 'eslint-config-vitest-globals/flat' for flat config usage.
gotcha Flat config export is a function, not a plain object; must be invoked as vitestGlobals().
fix Use vitestGlobals() instead of vitestGlobals.
deprecated ESLint v8 traditional config (.eslintrc) is deprecated; future updates may only support flat config.
fix Migrate to ESLint v9 flat config using 'eslint-config-vitest-globals/flat'.
gotcha Package only provides globals, not rules. You still need to configure 'no-undef' rule correctly; globals will suppress false positives.
fix Ensure 'no-undef' is enabled in your ESLint config. The globals set by this package will be recognized.
npm install eslint-config-vitest-globals
yarn add eslint-config-vitest-globals
pnpm add eslint-config-vitest-globals

Shows how to set up eslint-config-vitest-globals with ESLint v9 flat config, calling vitestGlobals() to register Vitest globals.

// Install: npm install --dev eslint eslint-config-vitest-globals

// eslint.config.js (ESLint v9+)
import vitestGlobals from 'eslint-config-vitest-globals/flat';

export default [
  vitestGlobals(),
  {
    files: ['**/*.test.js', '**/*.spec.js'],
    rules: {
      // your custom rules for test files
    }
  },
  // other configs
];