Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint cannot find the react-hooks/exhaustive-deps rule

ErrorDefinition for rule 'react-hooks/exhaustive-deps' was not found

Short answer

ESLint only knows a rule when the plugin that owns it is registered in the config that applies to the file. This error means eslint-plugin-react-hooks is not installed, is not listed under plugins, or was written in the old .eslintrc style while ESLint reads eslint.config.js. Register the plugin once in the config style your ESLint version uses.

  • Applies to ESLint 9, eslint-plugin-react-hooks (current release), Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which config style your project really uses. A file called eslint.config.js (or .mjs/.ts) means flat config; a .eslintrc file means the legacy style. Then check that the plugin is installed.

    ls -a | grep -i eslint
    npx eslint --version
    npm ls eslint-plugin-react-hooks
  2. 2Match what you see, then jump to its fix

    1. 1The rule name appears under rules, but no plugins entry named react-hooks exists next to itThe plugin is not registered in the configFix
    2. 2ESLint 9 or newer, a config with extends: ["plugin:react-hooks/recommended"], and the rule still not foundA legacy .eslintrc style config is read by a flat-config ESLintFix

What does the error look like?

  • Definition for rule 'react-hooks/exhaustive-deps' was not found
  • Definition for rule 'react-hooks/rules-of-hooks' was not found

Cause 1 of 2

The plugin is not registered in the config

1Check

Open your ESLint config and look for the plugin. A rule such as react-hooks/exhaustive-deps only exists after the react-hooks plugin has been loaded under that namespace.

grep -n "react-hooks" eslint.config.* .eslintrc* package.json 2>/dev/null

2Fix

Install the package as a dev dependency, then register it. In flat config, import it and add it under plugins. The plugin's own README also offers a ready-made recommended preset.

npm install eslint-plugin-react-hooks --save-dev

// eslint.config.js
import reactHooks from 'eslint-plugin-react-hooks';

export default [
  {
    files: ['**/*.{js,jsx,ts,tsx}'],
    plugins: { 'react-hooks': reactHooks },
    rules: {
      'react-hooks/rules-of-hooks': 'error',
      'react-hooks/exhaustive-deps': 'warn',
    },
  },
];

3Verify

Lint a file that uses a hook. The error about the missing definition is gone; real warnings can now appear.

npx eslint src/

Confirmed by github.com

Did this fix it?

Cause 2 of 2

A legacy .eslintrc style config is read by a flat-config ESLint

1Check

ESLint has used eslint.config.js as its default since v9.0.0. The plugin README documents the extends string only for the legacy .eslintrc format used by ESLint below 9, so mixing the two leaves the plugin unloaded.

npx eslint --version
ls -a | grep -iE "eslint(rc|\.config)"

2Fix

Move the setting into eslint.config.js and use the flat preset the plugin exports. If you must stay on ESLint 8, keep the legacy form instead.

// eslint.config.js (ESLint 9+)
import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';

export default defineConfig([
  reactHooks.configs.flat.recommended,
]);

// .eslintrc.json (ESLint below 9 only)
{ "extends": ["plugin:react-hooks/recommended"] }

3Verify

Run ESLint on the project and confirm the hooks rules report on a file you know has a missing dependency.

npx eslint src/

Confirmed by eslint.org

Did this fix it?

How do I stop it coming back?

  • Keep one config file per project and delete the other style when you migrate.
  • Pin eslint and eslint-plugin-react-hooks together in package.json so an upgrade changes both at once.
  • Prefer the plugin's recommended preset over copying rule names by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.