From 6b344c7c5359d0113389ef92d0a6a4d5cbb76677 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 22 Oct 2025 18:31:09 +0200 Subject: [PATCH 1/3] Switch to `export =` to fix eslint-plugin-react-hooks types (#34949) ## Summary Resolve the type error with the types, according to [Are the types wrong?](https://arethetypeswrong.github.io/?p=eslint-plugin-react-hooks%407.0.0), as an additional - Last attempt: https://github.com/facebook/react/pull/34746 - Original issue: https://github.com/facebook/react/issues/34745 ## How did you test this change? I edited `node_modules/eslint-plugin-react-hooks/index.d.ts` in my `"module": "Node16"` + `"type": "module"` project and my error went away: - https://github.com/facebook/react/issues/34801#issuecomment-3433053067 cc @poteto @michaelfaith @andrewbranch --- packages/eslint-plugin-react-hooks/npm/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/npm/index.d.ts b/packages/eslint-plugin-react-hooks/npm/index.d.ts index c883d6f8adf6c..7516dc1e846e2 100644 --- a/packages/eslint-plugin-react-hooks/npm/index.d.ts +++ b/packages/eslint-plugin-react-hooks/npm/index.d.ts @@ -5,4 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -export {default} from './cjs/eslint-plugin-react-hooks'; +import reactHooks from './cjs/eslint-plugin-react-hooks'; + +export = reactHooks; From bbb7a1fdf741eed6b7adcd48a441259819d664cc Mon Sep 17 00:00:00 2001 From: lauren Date: Wed, 22 Oct 2025 13:18:44 -0400 Subject: [PATCH 2/3] [eprh] Type `configs.flat` more strictly (#34950) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses #34801 where `configs.flat` is possibly undefined as it was typed as a record of arbitrary string keys. Screenshot 2025-10-22 at 1 16 44 PM --- packages/eslint-plugin-react-hooks/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/src/index.ts b/packages/eslint-plugin-react-hooks/src/index.ts index 6d72c1daa57a9..924299d898948 100644 --- a/packages/eslint-plugin-react-hooks/src/index.ts +++ b/packages/eslint-plugin-react-hooks/src/index.ts @@ -71,7 +71,10 @@ const configs = { plugins, rules: recommendedLatestRuleConfigs, }, - flat: {} as Record, + flat: {} as { + recommended: ReactHooksFlatConfig; + 'recommended-latest': ReactHooksFlatConfig; + }, }; const plugin = { From 723b25c6444e4dcabe710ae33bc93cea79324428 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Wed, 22 Oct 2025 20:05:49 +0200 Subject: [PATCH 3/3] Add hint for Node.js cjs-module-lexer for eslint-plugin-react-hook types (#34951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fix the runtime error with named imports and make the last remaining [Are The Types Wrong?](https://arethetypeswrong.github.io/?p=eslint-plugin-react-hooks%400.0.0-experimental-6b344c7c-20251022) error with `eslint-plugin-react-hooks` go away, thanks to the hint from @andrewbranch: - https://github.com/facebook/react/issues/34801#issuecomment-3433478810 ## How did you test this change? I tried adding this to `node_modules` and it fixed the failures when importing named imports like `import { configs, meta, rules } from 'eslint-plugin-react-hooks'`: ```bash ➜ eslint-config-upleveled git:(renovate/react-monorepo) pnpm eslint . --max-warnings 0 Oops! Something went wrong! :( ESLint: 9.37.0 file:///Users/k/p/eslint-config-upleveled/index.js:13 import reactHooks, { configs } from 'eslint-plugin-react-hooks'; ^^^^^^^ SyntaxError: Named export 'configs' not found. The requested module 'eslint-plugin-react-hooks' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using: import pkg from 'eslint-plugin-react-hooks'; const { configs } = pkg; at ModuleJob._instantiate (node:internal/modules/esm/module_job:228:21) at async ModuleJob.run (node:internal/modules/esm/module_job:335:5) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:647:26) at async dynamicImportConfig (/Users/k/p/eslint-config-upleveled/node_modules/.pnpm/eslint@9.37.0/node_modules/eslint/lib/config/config-loader.js:186:17) at async loadConfigFile (/Users/k/p/eslint-config-upleveled/node_modules/.pnpm/eslint@9.37.0/node_modules/eslint/lib/config/config-loader.js:276:9) at async ConfigLoader.calculateConfigArray (/Users/k/p/eslint-config-upleveled/node_modules/.pnpm/eslint@9.37.0/node_modules/eslint/lib/config/config-loader.js:589:23) at async #calculateConfigArray (/Users/k/p/eslint-config-upleveled/node_modules/.pnpm/eslint@9.37.0/node_modules/eslint/lib/config/config-loader.js:743:23) at async directoryFilter (/Users/k/p/eslint-config-upleveled/node_modules/.pnpm/eslint@9.37.0/node_modules/eslint/lib/eslint/eslint-helpers.js:309:5) at async NodeHfs. (file:///Users/k/p/eslint-config-upleveled/node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/hfs.js:586:29) at async NodeHfs.walk (file:///Users/k/p/eslint-config-upleveled/node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/hfs.js:614:3) ➜ eslint-config-upleveled git:(renovate/react-monorepo) pnpm eslint . --max-warnings 0 ➜ eslint-config-upleveled git:(renovate/react-monorepo) # no error ``` The named imports identifiers `configs`, `meta`, and `rules` also contain values, as a sanity check: - https://github.com/facebook/react/pull/34951#issuecomment-3433555636 cc @poteto --- packages/eslint-plugin-react-hooks/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/eslint-plugin-react-hooks/index.js b/packages/eslint-plugin-react-hooks/index.js index ce26a10c31518..4c18af7c001f7 100644 --- a/packages/eslint-plugin-react-hooks/index.js +++ b/packages/eslint-plugin-react-hooks/index.js @@ -1 +1,11 @@ module.exports = require('./src/index.ts'); + +// Hint to Node’s cjs-module-lexer to make named imports work +// https://github.com/facebook/react/issues/34801#issuecomment-3433478810 +// eslint-disable-next-line ft-flow/no-unused-expressions +0 && + (module.exports = { + meta: true, + rules: true, + configs: true, + });