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 #2728

Closed
sluukkonen opened this issue Jul 27, 2020 · 11 comments · Fixed by #2730
Closed

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

sluukkonen opened this issue Jul 27, 2020 · 11 comments · Fixed by #2730

Comments

@sluukkonen
Copy link

Version 7.20.4 seems to crash with the following error in a non-tsx file.

yarn run v1.22.4
$ prettier packages/core/src/**/*.less --check && eslint packages --ext .js,.ts,.tsx --cache
Checking formatting...
All matched files use Prettier code style!

Oops! Something went wrong! :(

ESLint: 7.5.0

TypeError: Cannot read property 'name' of null
Occurred while linting /home/runner/work/exam-engine/exam-engine/packages/cli/src/commands/create-mex.ts:23
    at Object.getStatelessComponent (/home/runner/work/exam-engine/exam-engine/node_modules/eslint-plugin-react/lib/util/Components.js:692:45)
    at Object.getParentStatelessComponent (/home/runner/work/exam-engine/exam-engine/node_modules/eslint-plugin-react/lib/util/Components.js:728:42)
    at Object.getParentComponent (/home/runner/work/exam-engine/exam-engine/node_modules/eslint-plugin-react/lib/util/Components.js:623:18)
    at Object.ArrowFunctionExpression (/home/runner/work/exam-engine/exam-engine/node_modules/eslint-plugin-react/lib/util/Components.js:916:31)
    at updatedRuleInstructions.<computed> (/home/runner/work/exam-engine/exam-engine/node_modules/eslint-plugin-react/lib/util/Components.js:970:43)
    at /home/runner/work/exam-engine/exam-engine/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/exam-engine/exam-engine/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/runner/work/exam-engine/exam-engine/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/home/runner/work/exam-engine/exam-engine/node_modules/eslint/lib/linter/node-event-generator.js:283:22)

I haven't been able to produce a reduced test case yet.

@xiekw2010
Copy link

+1

@PrimoZiv
Copy link

PrimoZiv commented Jul 27, 2020

I have same problem.

  // error:
  export default function () {}

  // success
  export default function name() {}

@bhovhannes
Copy link

Version 7.20.3 works fine.

@cy6erskunk
Copy link

cy6erskunk commented Jul 27, 2020

Seems to be caused by #2699

marusak added a commit to marusak/cockpit that referenced this issue Jul 27, 2020
yorkie added a commit to alibaba/pipcook that referenced this issue Jul 27, 2020
The eslint-plugin-react@7.20.4 introduced a crash bug when linting a source with anonymous function
with es module.

This PR removes all related anonymous functions to hotfix the problem.

See jsx-eslint/eslint-plugin-react#2728
@odinho
Copy link
Contributor

odinho commented Jul 27, 2020

Ah, I see someone also reduced it already. An easy null-check on the node.id.name before it's used will fix this issue. Here's a full testcase:

odin@kaa:~/tmp/a$ cat default_export_without_name.js
export default function() {}
odin@kaa:~/tmp/a$ cat package.json 
{
  "scripts": {
    "test": "eslint default_export_without_name.js"
  },
  "dependencies": {
    "eslint": "^7.5.0",
    "eslint-plugin-react": "^7.20.4"
  }
}
odin@kaa:~/tmp/a$ cat .eslintrc 
{
    "env": { "es6": true },
    "plugins": ["react"],
    "parserOptions": { "sourceType": "module" },
    "extends": [ "plugin:react/recommended" ],
    "settings": { "react": { "version": "latest" } } 
}

yorkie added a commit to alibaba/pipcook that referenced this issue Jul 27, 2020
The eslint-plugin-react@7.20.4 introduced a crash bug when linting a source with anonymous function
with es module.

This PR removes all related anonymous functions to hotfix the problem.

See jsx-eslint/eslint-plugin-react#2728
sluukkonen added a commit to digabi/exam-engine that referenced this issue Jul 27, 2020
This should work around the issue in eslint-plugin-react 7.20.4 [1], and
is good practice in any case.

[1] jsx-eslint/eslint-plugin-react#2728
marusak added a commit to cockpit-project/cockpit that referenced this issue Jul 27, 2020
@Roxyhuang
Copy link

Roxyhuang commented Jul 27, 2020

I have same problem.

@dukemai
Copy link

dukemai commented Jul 27, 2020

same problem here

@pevans01
Copy link

Same problem :-)

@odinho
Copy link
Contributor

odinho commented Jul 27, 2020

Instead of commenting, just click the 👍 on the top issue instead. Better for everyone ^_^

You may also help out with the PR at #2730 if it turns out anything is needed. Though currently just waiting on review from @ljharb. :)

@ljharb
Copy link
Member

ljharb commented Jul 28, 2020

Thanks everyone; I'll get a fix out tonight tomorrow.

ljharb added a commit to wKich/eslint-plugin-react that referenced this issue Jul 28, 2020
Fixes jsx-eslint#2728.

Co-authored-by: Odin Hørthe Omdal <odin.omdal@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Dmitriy Lazarev <w@kich.dev>
@edokeh
Copy link

edokeh commented Jul 28, 2020

+1

And version 7.20.3 works

gindis pushed a commit to gindis/pipcook that referenced this issue Sep 11, 2020
The eslint-plugin-react@7.20.4 introduced a crash bug when linting a source with anonymous function
with es module.

This PR removes all related anonymous functions to hotfix the problem.

See jsx-eslint/eslint-plugin-react#2728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.