microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.06k stars 12.49k forks source link

TS Server fatal error: Cannot read properties of undefined (reading 'flags') #56755

Closed rhhill1401 closed 3 months ago

rhhill1401 commented 11 months ago

Type: Bug

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

TypeScript Version: 5.4.0-dev.20231210

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 properties of undefined (reading 'flags')
    at getPropertyOfObjectType (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:59373:14)
    at getPropertyOfType (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:60000:14)
    at checkPropertyAccessExpressionOrQualifiedName (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:74966:14)
    at checkPropertyAccessExpression (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:74785:94)
    at checkExpressionWorker (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:80499:16)
    at checkExpression (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:80420:32)
    at checkExpressionCached (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:80090:28)
    at getTargetOfAliasLikeExpression (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50951:5)
    at getTargetOfExportAssignment (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50923:22)
    at getTargetOfAliasDeclaration (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50978:16)
    at resolveAlias (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51014:22)
    at resolveSymbol (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51004:59)
    at resolveExternalModuleSymbol (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51598:28)
    at getTargetOfImportEqualsDeclaration (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50453:25)
    at getTargetOfAliasDeclaration (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50964:16)
    at resolveAlias (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51014:22)
    at getSymbolFlags (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51045:61)
    at getSymbol2 (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49541:31)
    at resolveNameHelper (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49774:24)
    at resolveName (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49750:12)
    at resolveEntityName (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51220:32)
    at getTargetOfAliasLikeExpression (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50941:23)
    at getTargetOfExportAssignment (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50923:22)
    at getTargetOfAliasDeclaration (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:50978:16)
    at resolveAlias (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51014:22)
    at resolveSymbol (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:51004:59)
    at mergeSymbol (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49343:32)
    at /Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49453:37
    at Map.forEach (<anonymous>)
    at mergeSymbolTable (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49451:12)
    at mergeSymbol (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49365:9)
    at /Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49453:37
    at Map.forEach (<anonymous>)
    at mergeSymbolTable (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49451:12)
    at initializeTypeChecker (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:87794:9)
    at createTypeChecker (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:49105:3)
    at Object.getTypeChecker (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:122767:42)
    at synchronizeHostDataWorker (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:145575:13)
    at synchronizeHostData (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:145466:7)
    at Object.getProgram (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:145644:5)
    at ConfiguredProject2.updateGraphWorker (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:178301:41)
    at ConfiguredProject2.updateGraph (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:178150:32)
    at ConfiguredProject2.updateGraph (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:179402:24)
    at _ProjectService.createLoadAndUpdateConfiguredProject (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:181139:13)
    at _ProjectService.assignProjectToOpenedScriptInfo (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:182236:26)
    at /Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:182516:64
    at flatMap (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:2604:17)
    at _ProjectService.applyChangesInOpenFiles (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:182516:24)
    at updateOpen (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:183718:29)
    at /Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:186326:69
    at IpcIOSession.executeWithRequestId (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:186318:14)
    at IpcIOSession.executeCommand (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:186326:29)
    at IpcIOSession.onMessage (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:186368:51)
    at process.<anonymous> (/Users/terryhill/.vscode/extensions/ms-vscode.vscode-typescript-next-5.4.20231210/node_modules/typescript/lib/tsserver.js:187977:14)
    at process.emit (node:events:513:28)
    at emit (node:internal/child_process:937:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

VS Code version: Code 1.85.0 (Universal) (af28b32d7e553898b2a91af498b1fb666fdebe0c, 2023-12-06T18:18:04.614Z) OS version: Darwin arm64 22.3.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 Max (10 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|13, 21, 25| |Memory (System)|32.00GB (4.41GB free)| |Process Argv|--crash-reporter-id cccdf885-8e7f-4939-93f0-2262e8602702| |Screen Reader|no| |VM|0%|
Extensions (29) Extension|Author (truncated)|Version ---|---|--- better-comments|aar|3.0.2 vscode-tailwindcss|bra|0.10.3 path-intellisense|chr|2.8.5 vscode-eslint|dba|2.4.2 es7-react-js-snippets|dsz|4.4.3 gitlens|eam|14.5.2 vscode-html-css|ecm|1.13.1 EditorConfig|Edi|0.16.4 prettier-vscode|esb|10.1.0 copilot|Git|1.141.0 copilot-chat|Git|0.11.0 copilot-labs|Git|0.17.1121 vscode-graphql-syntax|Gra|1.2.2 vscode-react-typescript|inf|1.3.1 path-autocomplete|ion|1.25.0 git-graph|mhu|1.30.0 cmake-tools|ms-|1.16.32 cpptools|ms-|1.18.5 cpptools-extension-pack|ms-|1.3.0 vscode-typescript-next|ms-|5.4.20231210 vsliveshare|ms-|1.0.5900 nativebase-v3-vscode-extension|Nat|0.1.3 back-n-forth|nic|3.1.1 phind|phi|0.16.7 autoimport|ste|1.5.4 cmake|twx|0.0.17 vscode-gradle|vsc|3.13.5 vscode-icons|vsc|12.6.0 material-theme|zhu|3.16.2 (1 theme extensions excluded)
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 vslsvsres303:30308271 vserr242:30382549 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vsdfh931:30280409 vshan820:30294714 vstes263:30335439 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30410667 py29gd2263:30899288 vscaat:30438848 vsclangdf:30486550 c4g48928:30535728 dsvsc012:30540252 azure-dev_surveyone:30548225 282f8724:30602487 f6dab269:30613381 showlangstatbar:30737416 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 welcomedialogc:30910334 pythonnosmt12:30797651 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 dsvsc013:30795093 dsvsc014:30804076 dsvsc015:30845448 pythontestfixt:30902429 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 accentitlementsc:30887149 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 aa_t_chat:30882232 dsvsc019:30917259 ```
RyanCavanaugh commented 11 months ago

We'll definitely need the code that causes this crash. Can you share a repro? Thanks!

swissmanu commented 2 weeks ago

It seems I face the same/a similar problem with TypeScript 5.0.4:

/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:53470
    if (type.flags & 524288 /* Object */) {
             ^

TypeError: Cannot read properties of undefined (reading 'flags')
    at getPropertyOfObjectType (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:53470:14)
    at getPropertyOfType (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:54068:14)
    at checkPropertyAccessExpressionOrQualifiedName (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:68600:14)
    at checkPropertyAccessExpression (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:68425:94)
    at checkExpressionWorker (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:73954:16)
    at checkExpression (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:73874:32)
    at checkExpressionCached (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:73543:28)
    at getTargetOfAliasLikeExpression (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:45377:5)
    at getTargetOfExportAssignment (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:45349:22)
    at getTargetOfAliasDeclaration (/Users/manuel/git/insidelabs/omni-app/node_modules/typescript/lib/tsc.js:45404:16)

Node.js v20.18.0

I already tried upgrading to the latest stable and next versions of TypeScript; no improvement.

I would love to provide a repro for this. However, I face this situation during a major upgrade of a dependency of our code base and I have no idea where to start looking for the root cause. I tried passing --traceResolution and --extendedDiagnostics to tsc already, but somehow I am not sure if, e.g., the last resolved module is really a place to start at. How would you suggest I should get started @RyanCavanaugh?

Thanks already! 🙏

swissmanu commented 1 week ago

Alright, I was able to identify the problem in our code base: We had a rouge .d.ts file flying around from 5 years ago nobody was thinking of anymore:

declare module 'console' {
    export = typeof import('console');
}

By removing this type declaration file, tsc runs smooth again.

I do not understand why the definitions in that file crash tsc (yet). However, I want to share the steps used which lead me to the cause:

  1. Start tsc with enabled debugging: node ./node_modules/typescript/lib/tsc --inspect-brk.
  2. Open chrome://inspect, and connect to the waiting Node.js instance.
  3. Open tsc.js in the source tab, go to line 53470 based on the stack trace shared before and add a breakpoint.
  4. Run.
  5. Once the breakpoint hits,
    • inspect the origins of the type function parameter. No results.
    • inspect the call stack. High up, the call stack points to the initializeTypeChecker function.
  6. In this function, in the debugger, add a log point before the next function from the call stack gets called (in my case, this is mergeSymbolTable). Log the file variable. Hypothesis behind this log point: This should log the TypeScript source file which crashes tsc.
  7. Restart tsc with --inspect-brk and re-run the debugger.
  8. 🤩 Bingo! The last logged entry from the log point pointed straight to the .d.ts mentioned above: Image

If we cant identify the underlying problem in the TypeScript compiler, maybe the analysis steps help at least other people having the same issue :)

RyanCavanaugh commented 1 week ago

@swissmanu very good investigation. Do you have the rest of the code that triggers the crash? Putting that into a project, I'm not seeing any errors