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

TypeError: Cannot read property 'name' of null #2840

Closed
wereHamster opened this issue Oct 21, 2020 · 7 comments
Closed

TypeError: Cannot read property 'name' of null #2840

wereHamster opened this issue Oct 21, 2020 · 7 comments

Comments

@wereHamster
Copy link

export default class extends React.PureComponent<{}> {
  render() {
    return <div />
  }
}

The error is thrown in getDetectedComponents(), specifically line return val.node.id.name, where val.node is a ClassDeclaration with a null id.

@ljharb
Copy link
Member

ljharb commented Oct 21, 2020

While it's a very bad practice for debuggability to have an unnamed component, we certainly shouldn't crash on it.

@ljharb
Copy link
Member

ljharb commented Oct 21, 2020

Which rule is this crashing on?

@wereHamster
Copy link
Author

Not sure, I think I had all the recommended rules enabled (and only disabled a few which I don't need).

@ljharb
Copy link
Member

ljharb commented Oct 21, 2020

Could you provide the full stack trace?

@wereHamster
Copy link
Author

TypeError: Cannot read property 'name' of null
Occurred while linting …/src/pages/[locale]/countries.tsx:260
    at …/node_modules/eslint-plugin-react/lib/util/Components.js:580:28
    at Array.map (<anonymous>)
    at Object.getDetectedComponents (…/node_modules/eslint-plugin-react/lib/util/Components.js:578:10)
    at Object.nodeWrapsComponent (…/node_modules/eslint-plugin-react/lib/util/Components.js:592:34)
    at Object.isPragmaComponentWrapper (…/node_modules/eslint-plugin-react/lib/util/Components.js:605:20)
    at Object.CallExpression (…/node_modules/eslint-plugin-react/lib/util/Components.js:849:18)
    at updatedRuleInstructions.<computed> (…/node_modules/eslint-plugin-react/lib/util/Components.js:974:43)
    at …/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (…/node_modules/eslint/lib/linter/safe-emitter.js:45:38)

@wereHamster
Copy link
Author

wereHamster commented Oct 21, 2020

The whole file is something like this. Line 260 would be the line with return React.memo(…

export default class extends React.PureComponent {
  render() {
    return <Card />;
  }
}

const Card = (() => {
  return React.memo(({ }) => (
    <div />
  ));
})();

@ljharb
Copy link
Member

ljharb commented Oct 21, 2020

hmm, ok thanks :-) i'll try to make a repro case.

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

No branches or pull requests

2 participants