create-t3-turbo: bug: eslint-plugin-react-hooks throws TypeError: context.getSource is not a function
Provide environment information
System:
OS: macOS 14.4.1
CPU: (8) arm64 Apple M2
Memory: 1.60 GB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.0 - /usr/local/bin/node
Yarn: 1.22.21 - ~/Library/pnpm/yarn
npm: 10.5.0 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
bun: 1.0.29 - ~/.bun/bin/bun
Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman
Describe the bug
Apologies if this is an upstream issue but the eslint-plugin-react-hooks isn’t working with the current V9 setup.
In the ESLint console you can see the following error:
[Error - 13:45:42] An unexpected error occurred:
[Error - 13:45:42] TypeError: context.getSource is not a function
Occurred while linting /Users/euanmorgan/code/create-t3-turbo/apps/nextjs/src/app/_components/posts.tsx:46
Rule: "react-hooks/exhaustive-deps"
at visitFunctionWithDependencies (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1704:42)
at visitCallExpression (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1759:11)
at ruleErrorHandler (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/linter.js:1145:48)
at /Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at runRules (/Users/euanmorgan/code/create-t3-turbo/node_modules/eslint/lib/linter/linter.js:1184:40)
Link to reproduction
N/A
To reproduce
- Clone the latest create-t3-turbo
- Trigger an
eslint-plugin-react-hooksrule e.g. InCreatePostFormwrite a useEffect like
useEffect(() => {
console.log(form.getValues());
}, []);
- The error will then appear in the terminal and linting is broke for the file
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 13
- Comments: 18 (5 by maintainers)
Commits related to this issue
- inertia - fix eslint - https://github.com/t3-oss/create-t3-turbo/issues/984\#issuecomment-2210934687 — committed to Plebeian-Technology/sway by dcordz 2 years ago
- Inertia (#38) * inertia - remove redux and use inertia instead * inertia - add maryland svg, fix census query * inertia - fix notification subscriptions create/destroy, fix census lookup of con... — committed to Plebeian-Technology/sway by dcordz 2 years ago
- chore(deps): upgrade eslint-plugin-react-hooks to v5.1.0 Update React Hooks ESLint plugin to the latest version in both yarn.lock and package.json This fixed the issue where errors recognized by the... — committed to SwitchbackTech/compass by tyler-dane 2 years ago
- đź§ą Chore: Use Eslint v9's Flat Config (#260) * build(deps): Update ESLint and TypeScript ESLint dependencies Upgrade ESLint and TypeScript ESLint packages to their latest versions: - eslint: 9.20.1 ... — committed to SwitchbackTech/compass by tyler-dane 2 years ago
Solution can be found here
TL;DR
add
@eslint/compatto your repo and usefixupPluginRules.@EuanMorgan definitely not a solution, but as a temporary fix:
disabled that rule so i could at least run my linter in CI…
I believe this was introduced with #969.
I also have the same issue.
I think so too. Eslint 9 is not ready for nextJS.
eslint peerDependency in eslint-config-next is ^8.0.0 instead of ^9.0.0. https://github.com/vercel/next.js/blob/2a605af1547776f918a23e074eb9309cab18a0a7/packages/eslint-config-next/package.json#L24
Eslint 9.0.0 has a breaking change.
context.getAncestors()has been replaced withsourceCode.getAncestors(node)https://eslint.org/docs/latest/use/migrate-to-9.0.0#-removed-multiple-context-methodsFor now, changing Eslint version to ^8.56.0 seems to fix it
Hoping on the train too, just to provide extra context. Not sure why, in one of my public projects, it works fine. But in another private project, with the same
eslint.config.jsconfigurations and exact same versions ofeslint,eslint-plugin-react,eslint-plugin-react-hooks(and other relevant eslint plugin/config packages), it fails with the message “context.getSource is not a function” when evaluating under rule “react-hooks/rules-of-hooks”.For now, using the
@rcversion solves the problem, just that it makes me wonder if this is an indication of another underlying problem… may be just something to watch out for.eslint-plugin-react-hooks@rc(notbeta) has a newer version (5.1.0-rc-cc1ec60d0d-20240607) that works for me (witheslint@^9.4.0and@antfu/eslint-config@^2.20.0).Upgrading to v5.0.0 of eslint-plugin-react-hooks fixed it for me…no need for the compat package in my case.
still occuring to me
The issue seems to have been resolved in the canary release of
eslint-plugin-react-hooks.https://github.com/facebook/react/pull/28773
However, using some rules from
eslint-plugin-reactsuch asreact/display-nameor other recommended ones still doesn’t work. This is being addressed in https://github.com/jsx-eslint/eslint-plugin-react/issues/3699.