eslinttypescript-eslint

ESLint 9.x.x error typescript-eslint/parser


When creating the 9.x.x config for ESLint with TypeScript, I started getting an error:

Error: Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Parser: typescript-eslint/parser`

At the same time, eslint.config.js looked like this:

export default tseslint.config(
  { ignores: ["dist", "assets", "build", "node_modules", "public", "vite.config.ts"] },
  {
    extends: [
      js.configs.recommended,
      ...tseslint.configs.recommended,
      eslintConfigPrettier
    ],
    settings: {
      "import/resolver": {
        typescript: {
          project: "./tsconfig.json",
        },
      },
    },
    files: ["**/*.{ts,tsx}"],
    languageOptions: {
      sourceType: "module",
      parserOptions: {
        ecmaFeatures: {
          jsx: true,
        },
        ecmaVersion: "latest",
        project: ["./tsconfig.json", "tsconfig.node.json", "tsconfig.app.json"], // <- Here it is
      },
      globals: globals.browser,
    },
    plugins: {
      "react-hooks": reactHooks,
    },
    rules: {
      ...reactHooks.configs.recommended.rules,
      "@typescript-eslint/dot-notation": "error",
    }
  }
);

The parserOptions.project property has already been registered, but the error is still in place.


Solution

  • it turned out that it's not about parserOptions.project, but that there is no tsconfigRootDir: __dirname

    after adding

    import { fileURLToPath } from "url";
    import { dirname } from "path";
    
    const __filename = fileURLToPath(import.meta.url);
    const __dirname = dirname(__filename);
    
    // ...
          parserOptions: {
            ecmaFeatures: {
              jsx: true,
            },
            ecmaVersion: "latest",
            project: ["./tsconfig.json", "tsconfig.node.json", "tsconfig.app.json"],
            tsconfigRootDir: __dirname,
          }
    // ...
    

    Everything worked