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] TypeError: Cannot read property 'replace' of undefined Occurred while linting #2118

Closed
Alecell opened this issue Jun 4, 2021 · 7 comments

Comments

@Alecell
Copy link

Alecell commented Jun 4, 2021

I'm getting an annoying error that occurs every time I type the word import.

[Error - 11:30:59 AM] ESLint stack trace:
[Error - 11:30:59 AM] TypeError: Cannot read property 'replace' of undefined
Occurred while linting /home/alecell/projects/AFYA/medcel.site.v6/src/pages/components/g2SwtuVEbBfUM36JWk3Rsn/g2SwtuVEbBfUM36JWk3Rsn.tsx:2
    at checkFileExtension (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint-plugin-import/lib/rules/extensions.js:147:52)
    at checkSourceValue (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at checkSource (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint-module-utils/moduleVisitor.js:34:5)
    at /home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
    at NodeEventGenerator.applySelectors (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
    at NodeEventGenerator.enterNode (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint/lib/linter/node-event-generator.js:336:14)
    at CodePathAnalyzer.enterNode (/home/alecell/projects/AFYA/medcel.site.v6/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)

THis error pops up on the right bottom corner of the VS code:
image

I've disabled my eslint plugins one by one until I realize that this error only occurs only when I have this plugin o the plugin list.

Versions:
Editor: VS Code 1.56.2
Eslint: 7.27.0
Eslint extension: 2.1.20
eslint-plugin-import: 2.23.4

@ljharb
Copy link
Member

ljharb commented Jun 4, 2021

Thanks! Any idea what code it's crashing on?

@ljharb
Copy link
Member

ljharb commented Jun 4, 2021

ah, i see - when you have import, and it's invalid syntax but is also partially parsed.

@ljharb ljharb closed this as completed in 4079482 Jun 4, 2021
@Alecell
Copy link
Author

Alecell commented Jun 4, 2021

Wasn't a invalid syntax itself, while I'm typing that error occurs. I don't know if have to be considered a invalid syntax while typing. The error throws on cases like this:

import

function Component(props) {
  return (
    <div>
      My Component
    </div>
  );
}

export default Component;

An interesting thing about this is that the error only throw when I type the last character, the "t".

But I don't get it, is that a real bug or am I missing something?

@ljharb
Copy link
Member

ljharb commented Jun 4, 2021

It's not really a bug - it's more of an unintended consequence of your editor trying to run the linter on code that isn't actually valid syntax, which is why I couldn't add a regression test for it.

@Alecell
Copy link
Author

Alecell commented Jun 6, 2021

I see. Any tip of what could be happening? I have more projects that run this eslint plugin, on all of them I use the same editor and only one of them pops up that annoying error.

@ljharb
Copy link
Member

ljharb commented Jun 6, 2021

No idea - but the next release will include this fix anyways

@LeeMoonki

This comment has been minimized.

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

3 participants