Skip to content

Help with unknown error: filePath should be an absolute path, but got eslint.config.mjs #129

@SeawardSalmon6

Description

@SeawardSalmon6

Environment

Node version: v20.18.2
npm version: 10.8.2
Local ESLint version: 9.22.0
Global ESLint version: None
Operating System: Windows 11 / WSL 2

What parser are you using?

@typescript-eslint/parser

What did you do?

I was trying to run the config inspector in my project. It was originally written with .eslintrc.json from the old config and some weeks ago we bumped our ESLint to the latest version. We ran the compat tool from ESLint to update our config files to the new flat config format but for some reason I couldn't find out I can't get to use config inspector because of the error below.

Image

Configuration

Our current eslint.config.mjs is the following:

import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import vitest from '@vitest/eslint-plugin';
import _import from 'eslint-plugin-import';
import importHelpers from 'eslint-plugin-import-helpers';
import prettier from 'eslint-plugin-prettier';
import react from 'eslint-plugin-react';
import reactRefresh from 'eslint-plugin-react-refresh';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
  baseDirectory: __dirname,
  recommendedConfig: js.configs.recommended,
  allConfig: js.configs.all,
});

/** @type { import("eslint").Linter.Config[] } */
export default [
  {
    ignores: [
      '**/node_modules/',
      '**/dist/',
      '**/build/',
      '**/public/',
      '**/.eslintcache',
      '**/tsconfig.tsbuildinfo',
    ],
  },
  ...fixupConfigRules(
    compat.extends(
      'eslint:recommended',
      'plugin:@typescript-eslint/strict',
      'plugin:@typescript-eslint/stylistic',
      'plugin:import/recommended',
      'plugin:import/typescript',
      'plugin:react/recommended',
      'plugin:react-hooks/recommended',
      'plugin:react/jsx-runtime',
      'plugin:prettier/recommended',
    ),
  ),
  {
    plugins: {
      react: fixupPluginRules(react),
      prettier: fixupPluginRules(prettier),
      'react-refresh': reactRefresh,
      'import-helpers': importHelpers,
      import: fixupPluginRules(_import),
      '@vitest': vitest,
      '@typescript-eslint': fixupPluginRules(typescriptEslint),
    },

    languageOptions: {
      ...react.configs.recommended.languageOptions,

      globals: {
        ...globals.browser,
        ...globals.serviceworker,
      },

      parser: tsParser,
      ecmaVersion: 'latest',
      sourceType: 'module',

      parserOptions: {
        ecmaFeatures: {
          jsx: true,
        },

        project: './tsconfig.eslint.json',
      },
    },

    settings: {
      react: {
        version: 'detect',
      },

      'import/resolver': {
        alias: {
          map: [
            ['~', './src/'],
            ['~apis', './src/apis/'],
            ['~components', './src/components/'],
            ['~contexts', './src/contexts/'],
            ['~hooks', './src/hooks/'],
            ['~icons', './src/icons/'],
            ['~pages', './src/pages/'],
            ['~services', './src/services/'],
            ['~styles', './src/sass/'],
            ['~utils', './src/utils/'],
            ['~types', './src/types/'],
            ['~constants', './src/constants/'],
          ],

          extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.scss', '.css'],
        },
      },
    },

    rules: <projectRules>,
  },
];

Stack trace

Failed to load `eslint.config.js`.
Note that `@eslint/config-inspector` only works with the flat config format:
https://eslint.org/docs/latest/use/configure/configuration-files-new
Error: 'filePath' should be an absolute path, but got eslint.config.mjs.
    at OverrideTester.test (file:///home/salmon/icount/ic-admin/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js:191:19)
    at flatConfig.files (file:///home/salmon/icount/ic-admin/node_modules/@eslint/eslintrc/lib/flat-compat.js:122:73)
    at match (file:///home/salmon/.npm/_npx/fadb285f08a830ab/node_modules/@eslint/config-inspector/dist/cli.mjs:5377:11)
    at file:///home/salmon/.npm/_npx/fadb285f08a830ab/node_modules/@eslint/config-inspector/dist/cli.mjs:5389:10
    at Array.some (<anonymous>)
    at pathMatches (file:///home/salmon/.npm/_npx/fadb285f08a830ab/node_modules/@eslint/config-inspector/dist/cli.mjs:5384:44)
    at file:///home/salmon/.npm/_npx/fadb285f08a830ab/node_modules/@eslint/config-inspector/dist/cli.mjs:5924:8
    at ConfigArray.forEach (<anonymous>)
    at ConfigArray.getConfigWithStatus (file:///home/salmon/.npm/_npx/fadb285f08a830ab/node_modules/@eslint/config-inspector/dist/cli.mjs:5850:8)
    at matchFile (file:///home/salmon/.npm/_npx/fadb285f08a830ab/node_modules/@eslint/config-inspector/dist/cli.mjs:8097:43)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions