question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-unused-vars] `TypeError: Cannot read property 'type' of undefined` on first `import` when having private methods

See original GitHub issue

Tell us about your environment

Environment Info:

Node version: v14.4.0 npm version: v6.14.5 Local ESLint version: v7.7.0 (Currently used) Global ESLint version: Not found

What parser (default, Babel-ESLint, etc.) are you using?

@babel/eslint-parser

Please show your full configuration:

Configuration
{
  "env": {
    "browser": true,
    "es2020": true,
    "jest": true,
    "node": true
  },
  "extends": "eslint:recommended",
  "parser": "@babel/eslint-parser"
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

I have updated babel-eslint to new @babel/eslint-parser so I can make use of private methods (there was an error on previous ones that only allowed private properties). After doing so, I’m getting the error attached at the end.

The code at WebRtcPeerCore.js:30 is import EventEmitter from 'events', and the failing repository is https://github.com/piranna/kurento-utils-js/blob/master/src/WebRtcPeerCore.js (there’s another one, but it’s company private). It only happen when changing any of the arrow functions set to a private property to be a private method, like this:

// TODO eslint doesn't fully support private methods, replace arrow function
  #setVideoStream = stream =>
  {
    this.#videoStream = stream

    this.emit('setLocalVideo')
  }
  #setVideoStream(stream)
  {
    this.#videoStream = stream

    this.emit('setLocalVideo')
  }
eslint src/* testutils/* __tests__/*

What did you expect to happen?

Eslint parsing the file as normally does.

What actually happened? Please include the actual, raw output from ESLint.

Oops! Something went wrong! :(

ESLint: 7.7.0

TypeError: Cannot read property 'type' of undefined
Occurred while linting /home/piranna/Trabajo/Veedeo.me/kurento-utils-js/src/WebRtcPeerCore.js:30
    at collectUnusedVariables (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/rules/no-unused-vars.js:569:50)
    at collectUnusedVariables (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/rules/no-unused-vars.js:603:17)
    at collectUnusedVariables (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/rules/no-unused-vars.js:603:17)
    at collectUnusedVariables (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/rules/no-unused-vars.js:603:17)
    at Program:exit (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/rules/no-unused-vars.js:615:36)
    at /home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/home/piranna/Trabajo/Veedeo.me/kurento-utils-js/node_modules/eslint/lib/linter/node-event-generator.js:283:22)

Are you willing to submit a pull request to fix this bug?

Yes, I can write one with some guidance about what’s the source of this error.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
pirannacommented, Aug 23, 2020

Checked on two different projects, I confirm @babel/eslint-parser version 7.11.4 at last fix this 😄

1reaction
mdjermanoviccommented, Aug 18, 2020

Thanks for the info!

We can keep this issue open to see if the new @babel/eslint-parser version fixes the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'type' of undefined" with Flow ... - GitHub
[no-unused-vars] TypeError: Cannot read property 'type' of undefined on first import when having private methods #13575.
Read more >
React “no-unused-vars” and property undefined error
The errors are: Cannot read property 'user' of undefined; 'dispatch' is assigned a value but never used no-unused-vars.
Read more >
no-unused-vars - TypeScript ESLint
Disallow unused variables. Extending "plugin:@typescript-eslint/recommended" in an ESLint configuration enables this rule.
Read more >
error typeerror: cannot read properties of undefined ... - You.com
It is because there is no res object in the getAllUsers function. You need to create a mock response and request and pass...
Read more >
Google TypeScript Style Guide
Google's internal environment has different constraints on TypeScript than you ... For example, a check for unused code will flag a private property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found