Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: eslint-plugin-react-hooks "Cannot read property parent of null" #19810

Closed
twavv opened this issue Sep 11, 2020 · 12 comments · Fixed by #19815
Closed

Bug: eslint-plugin-react-hooks "Cannot read property parent of null" #19810

twavv opened this issue Sep 11, 2020 · 12 comments · Fixed by #19815

Comments

@twavv
Copy link

twavv commented Sep 11, 2020

This seems to happen when

  1. I take a component as a prop
  2. I use that component as a JSX constructor in a hook

Minimal repro:

export const Foo = ({ Component }) => {
  React.useEffect(() => {
    console.log(<Component />);
  }, []);
};
    "eslint-plugin-react-hooks": "^4.1.1",

Interestingly, this does NOT cause the error:

export const Foo = ({ component }) => {
  React.useEffect(() => {
    const Component = component;
    console.log(<Component />);
  }, []);
};
@twavv twavv added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 11, 2020
@ghost
Copy link

ghost commented Sep 11, 2020

I might be the same.

It happens when @typescript-eslint/parser is 4.1.0 and I ran yarn eslint.

yarn run v1.22.4
$ eslint ./src --ext .js,.jsx,.ts,.tsx
The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately.

Oops! Something went wrong! :(

ESLint: 7.8.1

TypeError: Cannot read property 'parent' of null

I think the issue of typescript-eslint is related.

fastFindReferenceWithParent in eslint-plugin-react-hooks returns null...

@eps1lon eps1lon added Component: ESLint Rules Type: Bug and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Sep 11, 2020
@eps1lon
Copy link
Collaborator

eps1lon commented Sep 11, 2020

Confirmed with @typescript-eslint/parser 4.x. Interestingly by fixing it we can implement #18051 for @typescript-eslint/parser@^4.0. I'll follow-up with a PR. We might need to partition the tests by parser and not language.

@gaearon
Copy link
Collaborator

gaearon commented Sep 11, 2020

Fix in eslint-plugin-react-hooks@4.1.2.

@ghost
Copy link

ghost commented Sep 14, 2020

@eps1lon Thank you for solving this.

@damiangreen
Copy link

damiangreen commented Sep 24, 2020

I'm still seeing this

The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately.
The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately.
The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately.
The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately.
The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately.

with the latest dependencies

eslint-plugin-react-hooks@4.1.2,
@typescript-eslint/parser": "^4.2.0,
@typescript-eslint/eslint-plugin": "^4.2.0"
eslint": "^7.9.0"

Unfortunately it doesn't show me which line of code/ components are causing this to error.
And the build continues fine..

@Antonio-Laguna
Copy link

Same as @damiangreen here.

@twavv
Copy link
Author

twavv commented Sep 30, 2020

You should probably create a new issue.

@LauraBeatris
Copy link

@travigd I don't think so, since it's the same error

@twavv
Copy link
Author

twavv commented Sep 30, 2020

A new issue is likely to be seen by the relevant people more easily since it's not closed. And at least the error I reported in the issue above was actually fixed, even if it's the same error message.

@LauraBeatris
Copy link

@travigd Makes sense! I'll create another issue for it

@damiangreen
Copy link

@LauraBeatris did you make the issue? if so can you mention it in this thread. as this is the top Google result..

@LauraBeatris
Copy link

@damiangreen Just created #19940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants