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

[2.5.0-2.6.0] Parsing error: Cannot read property 'parent' of null #1114

Closed
le0nik opened this issue Oct 20, 2019 · 15 comments · Fixed by #1120
Closed

[2.5.0-2.6.0] Parsing error: Cannot read property 'parent' of null #1114

le0nik opened this issue Oct 20, 2019 · 15 comments · Fixed by #1120
Labels
bug Something isn't working has pr there is a PR raised to close this package: parser Issues related to @typescript-eslint/parser

Comments

@le0nik
Copy link

le0nik commented Oct 20, 2019

Repro: https://github.com/le0nik/typescript-eslint-parsing-repro.

There is a problem with @typescript-eslint/parser when eslint is executed in IDE/Editor(not in CLI) when you create a new file and add an import/export with curly braces anywhere in it. It triggers the following error: Parsing error: Cannot read property 'parent' of null .

Stack trace:

TypeError: Cannot read property 'parent' of null
    at Object.convertComments (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/convert-comments.js:115:31)
    at Object.astConverter (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js:36:46)
    at Object.parseAndGenerateServices (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:295:49)
    at Object.parseForESLint (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/parser/dist/parser.js:55:51)
    at parse (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:643:22)
    at Linter._verifyWithoutProcessors (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1093:33)
    at Linter._verifyWithConfigArray (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1236:21)
    at Linter.verify (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1191:25)
    at Linter.verifyAndFix (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1381:29)
    at verifyText (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/cli-engine/cli-engine.js:231:48)

Affected versions of @typescript-eslint/parser: 2.5.0-2.6.0

Some examples:

import { namedExport } from './util'; // error!!!

const a = {}; // no error, `{}` not in `import/export`

export const foo1 = () => 'foo'; // no error
export const foo2 = () => {}; // error!!!
export const foo3 = () => ({ a: 'b' }); // error!!!
export const foo4 = () => ([ // error!!!
  { a: 'b' }, 
])
export default { c: 'd' }; // error!!!

So in summary:

  • error is only present in IDE, not in CLI
  • error is only present in newly created files, not in files that already existed when project was opened in IDE(or when IDE was launched)
  • error is only present when you add curly braces inside import/export
@le0nik le0nik added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Oct 20, 2019
@bradzacher bradzacher added the bug Something isn't working label Oct 20, 2019
@le0nik le0nik changed the title [2.4.1-alpha.8] Parsing error: Cannot read property 'parent' of null [2.5.0] Parsing error: Cannot read property 'parent' of null Oct 21, 2019
@le0nik
Copy link
Author

le0nik commented Oct 21, 2019

Error is still present with 2.5.0. Changed title to reflect it.

@bradzacher
Copy link
Member

It's weird - sometimes I can repro this, sometimes I cannot.
For example, if I paste your first failing code example into new or old file, it works as expected.

But I have run into this sometimes in other files.
It's also annoying because ESLint swallows the exception, so it's hard to debug this.

https://github.com/eslint/eslint/blob/7c8bbe0391944e1f92e083a04715bf4b3fe6be5d/lib/linter/linter.js#L667

@le0nik
Copy link
Author

le0nik commented Oct 21, 2019

I tried to create a minimal repro https://github.com/le0nik/typescript-eslint-parsing-repro and listed steps for reproduction in the README. I can almost consistently reproduce it(sometimes Eslint doesn't give me the error, probably because of an internal error or a race condition inside of it, so I need to rename the variable and save file again for it to work).

I've updated the original post with an interesting thing I've found:

export const baz1 = () => 'foo'; // no error
export const baz2 = () => {} ; // error!!!
export baz3 = () => ([ // error!!!
  { a: 'b' }, // if you remove this object, the error is gone
]);
export default {}; // error!!!

This error only occurs when eslint sees {} after import or export in any way, like if it's a named import or if we export anything that has {}.

So inititally my assumption that default export didn't trigger the error was wrong. It does happen with default export, too.

@le0nik
Copy link
Author

le0nik commented Oct 21, 2019

Here's an error stack I've extracted:

"TypeError: Cannot read property 'parent' of null
    at Object.convertComments (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/convert-comments.js:115:31)
    at Object.astConverter (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js:36:46)
    at Object.parseAndGenerateServices (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:295:49)
    at Object.parseForESLint (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/parser/dist/parser.js:55:51)
    at parse (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:643:22)
    at Linter._verifyWithoutProcessors (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1093:33)
    at Linter._verifyWithConfigArray (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1236:21)
    at Linter.verify (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1191:25)
    at Linter.verifyAndFix (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1381:29)
    at verifyText (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/cli-engine/cli-engine.js:231:48)"

So looks like container is supposed to exist here, but it's null.

getNodeContainer also seems to guarantee return value to be a container object.

@bradzacher
Copy link
Member

bradzacher commented Oct 21, 2019

Hmm.. If it's that particular error, it's existed for a while, it's dodgy types.
I've had a WIP PR to fix that particular dodgy type before, but it was for an unrelated error.

I'll put up a new PR to fix that.

Thanks for helping debug this!!!

@bradzacher bradzacher removed the triage Waiting for maintainers to take a look label Oct 21, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label Oct 21, 2019
@le0nik
Copy link
Author

le0nik commented Oct 21, 2019

Thanks for working on this!

@G-Rath
Copy link
Contributor

G-Rath commented Oct 24, 2019

@bradzacher I don't know if this is related, but I don't feel I have enough to make an issue out of it:

I've got a weird somewhat related interminte bug that seems to be related to 2.5.0 as well in IntelliJ, reported here.

Heres a recording:

http://recordit.co/8Ku8tC2Kkk

This goes away if I don't use 2.5.0, but my brains too fried by some recent long work weeks to do my typical deep dive in trying to nail down a reproduction.

I've passed this issue on to a member of the WebStorm team, who might have a better shot at reproducing, but also feel free to @ me w/ instructions on how I could get more info for you :)

I'm on Windows 10.

@valadas
Copy link

valadas commented Oct 24, 2019

I am having the same issue, reverting to "@typescript-eslint/parser": "2.4.0" solved it temporarily...

momocow pushed a commit to momocow/node-cq-websocket that referenced this issue Oct 24, 2019
momocow pushed a commit to momocow/node-cq-websocket that referenced this issue Oct 24, 2019
@zoton2
Copy link

zoton2 commented Oct 24, 2019

Same issue as @G-Rath here, downgrading to 2.4.0 worked too although it still seems to break in this fashion on 2.4.0 if the root workspace folder is not the root of my project (where node_modules/eslint settings are). I didn't try to downgrade further as I didn't feel it worth my time.

@miguelyoobic95
Copy link

I can confirm I have the same issue on my end

@bradzacher
Copy link
Member

Please try v2.6.0 (released yesterday).
There was a fix within that release which (I believe) might have tangentially fixed this issue.

@le0nik
Copy link
Author

le0nik commented Oct 30, 2019

2.6.0 didn't fix it for me. I've updated repro to use the new version.

@le0nik le0nik changed the title [2.5.0] Parsing error: Cannot read property 'parent' of null [2.4.0-2.6.0] Parsing error: Cannot read property 'parent' of null Oct 30, 2019
pinkiesky added a commit to pinkiesky/timetable-bspu that referenced this issue Oct 30, 2019
@le0nik le0nik changed the title [2.4.0-2.6.0] Parsing error: Cannot read property 'parent' of null [2.5.0-2.6.0] Parsing error: Cannot read property 'parent' of null Oct 31, 2019
@rfgamaral
Copy link

@bradzacher Can we assume the real fix will come with 2.7.0?

@bradzacher
Copy link
Member

#1120 should have fixed the comment parsing code, which I believe was the root cause of this issue.

We have an automated release that runs every monday morning and publishes whatever is in master, so that PR will be pushed out as part of the release today (should be 2.6.1, because there were only fix commits since hte last release).

@rfgamaral
Copy link

#1120 should have fixed the comment parsing code, which I believe was the root cause of this issue.

We have an automated release that runs every monday morning and publishes whatever is in master, so that PR will be pushed out as part of the release today (should be 2.6.1, because there were only fix commits since hte last release).

Cool. Thanks for the clarification on the release process :)

ruddell added a commit to ruddell/generator-jhipster that referenced this issue Nov 18, 2019
"npm start" occasionally crashes due eslint failing with the error:
Parsing error: Cannot read property 'parent' of null
Related to typescript-eslint/typescript-eslint#1114
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants