eslint-plugin-react-native: [3.9.1] Crash related to
Hey! 👋
I’m getting Error: Couldn't find a Program
after upgrading this package from 3.8.1 to 3.9.1.
Bit of a contrived example below, but seems to reliably trigger the issue and was just about the smallest repro I could manage to find. Not able to post the actual code we’re using I’m afraid but it’s essentially rendering something like:
Total: 12.34
Seems to be something to do with nested text that has a function defined somewhere inside. In our case there’s a reducer for calculating a total.
Some notes:
- Using a named fn instead of the arrow fn still crashes - i.e.
arr.reduce(function add(acc, value) { return acc + value }, 0)
- Replacing the reducer callback with something else like a string prevents the crash - i.e.
arr.reduce('blah', 0)
(obviously invalid code though) - Defining the reducer callback outside of the JSX also prevents the crash - i.e.
const add = (acc, value) => acc + value
andarr.reduce(add, 0)
<- looks like this is a reasonable workaround for now…
Repro code:
const Comp = () => {
return (
<Text>
<Text>Text</Text> {fn(() => {})}
</Text>
)
}
> eslint .
Oops! Something went wrong! :(
ESLint: 7.8.1
Error: Couldn't find a Program
Occurred while linting /Users/REDACTED/REDACTED/REDACTED.tsx:XX
at Scope.getProgramParent (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/scope/index.js:813:11)
at Scope.registerBinding (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/scope/index.js:574:25)
at Scope.crawl (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/scope/index.js:729:14)
at Scope.init (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/scope/index.js:709:12)
at NodePath.setScope (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/path/context.js:131:30)
at NodePath.setContext (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/path/context.js:147:8)
at NodePath.pushContext (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/path/context.js:213:8)
at TraversalContext.visitQueue (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/context.js:100:14)
at TraversalContext.visitMultiple (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/context.js:79:17)
at TraversalContext.visit (/Users/REDACTED/REDACTED/node_modules/@babel/traverse/lib/context.js:138:19)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 36
- Comments: 31 (2 by maintainers)
Commits related to this issue
- build: update eslint-plugin-react-native to hsource's v4.0.0-wanderlog.2 Includes patch for Intellicode/eslint-plugin-react-native#270 — committed to ProgPrak-Native-App/react-native-app by MHajoha 2 years ago
- build: update eslint-plugin-react-native to hsource's v4.0.0-wanderlog.2 Includes patch for Intellicode/eslint-plugin-react-native#270 — committed to ProgPrak-Native-App/react-native-app by MHajoha 2 years ago
- Add more eslint rules (#4672) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily unde... — committed to software-mansion/react-native-reanimated by Latropos a year ago
- Add more eslint rules (#4672) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily unde... — committed to software-mansion/react-native-reanimated by Latropos a year ago
- Add more eslint rules (#4672) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily unde... — committed to software-mansion/react-native-reanimated by Latropos a year ago
Came up with a workaround 😄
This is still present in 3.11.0.
Really appreciate the amount of attention this gets from the maintainers.
The minimum conditions to reproduce this linting crash are: => Having a component with a function passed as a prop AND any kind of children.
So, the minimal reproducible example is the following one:
<MyComponent myFunctionProp={() => {}}>my children</MyComponent>;
To fix this issue, you should define the prop before passing it, like so:
Still getting this issue on:
eslint 7.14.0 eslint-plugin-react-native: 3.11.0
😕
Any timeline on the possibility of the PR that fixes it being merged?
Is this ever going to be fixed? This is a major issue.
#314 should fix this
I’m also getting this error with both arrow functions on
onPress
and theText
issue. It happens while coding on VSCode by showing a popup with text “ESLint: Couldn’t find a Program Occurred while linting…” and also when trying to commit via precommit hooks.Package.json:
.eslintrc.json
Using node v14.16.0
Same issue here with
eslint-plugin-react-native@3.10.0
when trying to use a arrow function inside JSX: