Skip to content

TS Server fatal error: Cannot read property 'flags' of undefined #47299

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

Closed
vinniciusgomes opened this issue Jan 3, 2022 · 10 comments · Fixed by #47348
Closed

TS Server fatal error: Cannot read property 'flags' of undefined #47299

vinniciusgomes opened this issue Jan 3, 2022 · 10 comments · Fixed by #47348
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fixed A PR has been merged for this issue

Comments

@vinniciusgomes
Copy link

Issue Type: Bug

❗️❗️❗️ Please fill in the sections below to help us diagnose the issue ❗️❗️❗️

TypeScript Version: 4.5.4

Steps to reproduce crash
1.
2.
3.

TS Server Log
❗️Server logging disabled. To help us fix crashes like this, please enable logging by setting:

"typescript.tsserver.log": "verbose"

After enabling this setting, future crash reports will include the server log.

TS Server Error Stack
Server: semantic

TypeError: Cannot read property 'flags' of undefined
    at getPropertyOfObjectType (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:57011:22)
    at getPropertyOfType (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:57671:24)
    at resolveESModuleSymbol (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49817:54)
    at getTargetOfNamespaceImport (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49002:28)
    at getTargetOfAliasDeclaration (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49236:28)
    at resolveAlias (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49281:30)
    at getSymbol (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47838:38)
    at resolveNameHelper (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:48131:34)
    at resolveName (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:48114:20)
    at resolveEntityName (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49453:42)
    at resolveEntityName (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49461:33)
    at getSymbolOfPartOfRightHandSideOfImportEquals (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49413:24)
    at getTargetOfImportEqualsDeclaration (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:48865:28)
    at getTargetOfAliasDeclaration (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49232:28)
    at resolveAlias (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49281:30)
    at resolveSymbol (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:49271:67)
    at mergeSymbol (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47624:42)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47739:47
    at Map.forEach (<anonymous>)
    at mergeSymbolTable (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47737:20)
    at mergeSymbol (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47648:21)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47739:47
    at Map.forEach (<anonymous>)
    at mergeSymbolTable (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47737:20)
    at mergeModuleAugmentation (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47753:17)
    at initializeTypeChecker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:85046:25)
    at Object.createTypeChecker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:47395:9)
    at Object.getTypeChecker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:114404:79)
    at synchronizeHostData (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:159898:21)
    at Object.getProgram (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:160019:13)
    at AutoImportProviderProject.Project.updateGraphWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:165033:53)
    at AutoImportProviderProject.Project.updateGraph (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:164962:42)
    at AutoImportProviderProject.updateGraph (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:165807:70)
    at Object.updateProjectIfDirty (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:166444:45)
    at ConfiguredProject.Project.getPackageJsonAutoImportProvider (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:165582:32)
    at ConfiguredProject.Project.updateGraph (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:165000:26)
    at ConfiguredProject.updateGraph (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:165955:63)
    at ProjectService.createLoadAndUpdateConfiguredProject (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:167679:25)
    at ProjectService.assignProjectToOpenedScriptInfo (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:168762:44)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:169102:97
    at Object.flatMap (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:522:25)
    at ProjectService.applyChangesInOpenFiles (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:169102:41)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:170260:46)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:172193:88
    at IOSession.Session.executeWithRequestId (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:172184:28)
    at IOSession.Session.executeCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:172193:33)
    at IOSession.Session.onMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:172219:35)
    at Interface.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:174824:31)
    at Interface.emit (events.js:315:20)
    at Interface._onLine (readline.js:337:10)
    at Interface._normalWrite (readline.js:482:12)
    at Socket.ondata (readline.js:194:10)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)

VS Code version: Code - Insiders 1.64.0-insider (Universal) (9930557, 2022-01-03T05:15:53.904Z)
OS version: Darwin arm64 21.2.0
Restricted Mode: No

System Info
Item Value
CPUs Apple M1 (8 x 24)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 4, 6
Memory (System) 8.00GB (0.25GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (24)
Extension Author (truncated) Version
better-comments aar 2.1.0
html-snippets abu 0.2.1
npm-intellisense chr 1.4.0
path-intellisense chr 2.6.0
bracket-pair-colorizer-2 Coe 0.2.2
vscode-eslint dba 2.2.2
gitlens eam 11.7.0
vscode-html-css ecm 1.10.2
EditorConfig Edi 0.16.4
vscode-npm-script eg2 0.3.23
prettier-vscode esb 9.0.0
auto-close-tag for 0.5.13
auto-rename-tag for 0.1.9
copilot Git 1.7.4421
vscode-pull-request-github Git 0.35.2021123010
vscode-codemetrics kis 1.24.0
dotenv mik 1.0.1
color-highlight nau 2.5.0
vscode-versionlens pfl 1.0.9
material-icon-theme PKi 4.11.0
LiveServer rit 5.6.1
vscode-styled-components sty 1.7.2
highlight-matching-tag vin 0.10.1
JavaScriptSnippets xab 1.8.0

(1 theme extensions excluded)

A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythontb:30258533
pythonptprofiler:30281269
vshan820:30294714
pythondataviewer:30285072
vscod805cf:30301675
pythonvspyt200:30323110
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30404738
vscop804cf:30404767
vscop341:30404997
vsclayoutctrc:30405799
py55gd98:30408621
vscexrecpromp3c:30407757
azactmsal:30409287

@ghost ghost assigned mjbvz Jan 3, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Jan 3, 2022

Please share a small project that triggers this issue so we can investigate this

@mjbvz mjbvz transferred this issue from microsoft/vscode Jan 3, 2022
@mjbvz mjbvz removed their assignment Jan 3, 2022
@otto-liljalaakso-nt
Copy link

Please share a small project that triggers this issue so we can investigate this

Does this help?

#47038 (comment)

@mjbvz
Copy link
Contributor

mjbvz commented Jan 5, 2022

@otto-urpelainen-nt Thanks but that was reported with an old TS version. We need a repo that still crashes with TS 4.5.4 too

@otto-liljalaakso-nt
Copy link

@otto-urpelainen-nt Thanks but that was reported with an old TS version. We need a repo that still crashes with TS 4.5.4 too

I think it does crash with exactly that version.
At least that is what is written into that repo's package.lock.

There was a different problem with that repo though,
see this pull request in the reproducer repository: ttamminen/tsc-crash#1

@andrewbranch
Copy link
Member

That repo looks completely unrelated. This issue and the attached stack trace can only possibly happen in an editor running TS Server. This repo demonstrates some simple compilation errors with tsc that are working as intended.

@otto-liljalaakso-nt
Copy link

otto-liljalaakso-nt commented Jan 5, 2022

That repo looks completely unrelated. This issue and the attached stack trace can only possibly happen in an editor running TS Server. This repo demonstrates some simple compilation errors with tsc that are working as intended.

It is related, but in an indirect way.
I do understand that the relation may be too indirect to be useful for debugging this issue.
The situation is explained in the comment I linked above,
but let me go through this once more.

So, we can reproduce this issue in our proprietary, large repository.
It manifests in two different ways:
as exact the issue reported in this ticket,
and as tsc crash during compilation:

$ yarn build
/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:47148
            if (type.flags & 524288) {
                     ^

TypeError: Cannot read property 'flags' of undefined
    at getPropertyOfObjectType (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:47148:22)
    at getPropertyOfType (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:47710:24)
    at resolveESModuleSymbol (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:40904:54)
    at getTargetOfNamespaceImport (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:40191:28)
    at getTargetOfAliasDeclaration (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:40405:28)
    at resolveAlias (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:40446:30)
    at getSymbol (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:39225:38)
    at resolveNameHelper (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:39464:34)
    at resolveName (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:39448:20)
    at resolveEntityName (/home/otto/src/Novatron/manage/xmevents/node_modules/typescript/lib/tsc.js:40573:42)

The call stack looks very similar for both problems!

Thanks to excellent debugging effort of @ttamminen,
the problem was traced to these two lines we have somewhere in the repository:

import FullCalendar from "@fullcalendar/react"
import { EventInput } from "@fullcalendar/core"

The reproducer repository is a minimal example having those lines and tsc.
For some reason, there VS Code functions as expected and there is no tsc crash.
But there are regular looking compilation errors.
Applying the fix for those in our main repo
also solves the "Cannot read property 'flags' of undefined" issue,
both for VS Code and the tsc run.

Let me know if this is still to indirect to get forward.
If so, I will not bother you any more with this,
and hope that eventually, somebody will encounter the issue in an open source project.

@andrewbranch
Copy link
Member

Unfortunately, it’s a total coincidence that https://github.com/ttamminen/tsc-crash has the same fix as the crash you’re experiencing. The repro you are experiencing in your proprietary codebase does indeed look related, but the supposed minimal repro is in fact completely unrelated. If you can give me private read access to your proprietary repo, then we can make some progress on this problem. But sadly https://github.com/ttamminen/tsc-crash doesn’t help with it 😕

@otto-liljalaakso-nt
Copy link

otto-liljalaakso-nt commented Jan 6, 2022

Unfortunately, it’s a total coincidence that https://github.com/ttamminen/tsc-crash has the same fix as the crash you’re experiencing. The repro you are experiencing in your proprietary codebase does indeed look related, but the supposed minimal repro is in fact completely unrelated. If you can give me private read access to your proprietary repo, then we can make some progress on this problem. But sadly https://github.com/ttamminen/tsc-crash doesn’t help with it 😕

Thank you for taking a look at this.
And sorry for giving such bad reproducer.

I put some effort to this and distilled a better reproducer from our repository.
I kept removing parts as long as the issue kept appearing.
The result is in this repository: otto-urpelainen-nt/tsc-crash-reproducer.
I can reproduce the original issue there in three different setups:
Linux, WSL 2 with VS Code remoting, Windows (needs a bit of workaround, because yarn does not play nice with PowerShell)

If this is still not useful,
I can try to get a permission for privately sharing the original repository.

@andrewbranch
Copy link
Member

Yes, that repros for me! Thank you so much @otto-urpelainen-nt, I know it’s not easy to create a minimal repro from a huge project. We were really stuck and now we’re not 🥳

@ttamminen
Copy link

@andrewbranch @otto-urpelainen-nt Excellent!

Great work Otto and thank you, Andrew, for taking look at this. I on the other hand have to check (out of curiosity) what were the differences between our repos. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fixed A PR has been merged for this issue
Projects
None yet
6 participants