TypeScript: tsserver crashes when adding an `import` statement above an existing `import` statement

From @vitosamson on June 16, 2017 14:7

I wasn’t sure if this should go in the typescript repo or here, but I’m reporting it here since it’s only reproducible in vscode. I don’t know enough about the language server to determine if this is an issue with the server itself, or the way that vscode is communicating with it.

In a file with the following contents:

import { foo } from './foo';

Insert a new line above and start typing a new import statement:

import { bar } from './bar';
import { foo } from './foo';

The problems tab reports the following error: [ts] Cannot find name 'impor' and then completely craps out.

There’s no issue if you add the new import statement below the existing one.

tsserver log shows the following:

Info 205  request: {"seq":70,"type":"request","command":"completionEntryDetails","arguments":{"file":"/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts","line":1,"offset":2,"entryNames":["import"]}}
Err 206   Exception on executing command {"seq":70,"type":"request","command":"completionEntryDetails","arguments":{"file":"/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts","line":1,"offset":2,"entryNames":["import"]}}:
Debug Failure.
Error: Debug Failure.
    at parseUpdateExpression (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17313:22)
    at parseUnaryExpressionOrHigher (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17241:40)
    at parseBinaryExpressionOrHigher (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17105:31)
    at parseAssignmentExpressionOrHigher (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:16885:24)
    at parseExpression (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:16858:24)
    at parseModuleSpecifier (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18866:24)
    at parseImportDeclarationOrImportEqualsDeclaration (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18821:49)
    at parseDeclaration (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18271:28)
    at parseStatement (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18241:32)
    at parseListElement (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:15953:20)
Info 207  response: {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":70,"success":false,"message":"Error processing request. Debug Failure. \nError: Debug Failure. \n    at parseUpdateExpression (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17313:22)\n    at parseUnaryExpressionOrHigher (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17241:40)\n    at parseBinaryExpressionOrHigher (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17105:31)\n    at parseAssignmentExpressionOrHigher (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:16885:24)\n    at parseExpression (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:16858:24)\n    at parseModuleSpecifier (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18866:24)\n    at parseImportDeclarationOrImportEqualsDeclaration (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18821:49)\n    at parseDeclaration (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18271:28)\n    at parseStatement (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:18241:32)\n    at parseListElement (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:15953:20)"}
Info 208  request: {"seq":71,"type":"request","command":"change","arguments":{"file":"/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts","line":1,"offset":7,"endLine":1,"endOffset":7,"insertString":" "}}
Perf 209  71::change: async elapsed time (in milliseconds) 0.1712
Info 210  request: {"seq":72,"type":"request","command":"geterr","arguments":{"delay":0,"files":["/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts"]}}
Perf 211  72::geterr: async elapsed time (in milliseconds) 0.3331
Err 212   Exception on executing command syntactic check:
Debug Failure.
Error: Debug Failure.
    at tryReuseStructureFromOldProgram (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:56936:22)
    at Object.createProgram (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:56756:34)
    at synchronizeHostData (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:74129:33)
    at Object.getProgram (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:74187:13)
    at ConfiguredProject.Project.updateGraphWorker (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:77164:53)
    at ConfiguredProject.Project.updateGraph (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:77122:39)
    at ConfiguredProject.Project.getLanguageService (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:76901:26)
    at IOSession.Session.syntacticCheck (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:79488:41)
    at checkOne (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:79521:35)
    at MultistepOperation.executeAction (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:79058:25)
Info 213  event: {"seq":0,"type":"event","event":"semanticDiag","body":{"file":"/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts","diagnostics":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":7},"text":"Cannot find name 'impor\n'.","code":2304,"category":"error"},{"start":{"line":2,"offset":8},"end":{"line":2,"offset":12},"text":"'foo' is declared but never used.","code":6133,"category":"error"}]}}
Info 214  event: {"seq":0,"type":"event","event":"requestCompleted","body":{"request_seq":72}}

This is occurring when I set vscode to use the workspace TS version, which is 2.4.0. The problem does not appear when using vscode’s version, which is 2.3.4.

  • VSCode Version: 1.13.1
  • Typescript version: 2.4.0
  • OS Version: OS X 10.11.1
  • Extensions: none

Copied from original issue: Microsoft/vscode#28882

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Same issue here with 2.4 RC.

For now, I very crudely fixed it by replacing Debug.assert with a no-op:

sed -i "s/Debug.assert = assert/Debug.assert = function() {}/" node_modules/typescript/lib/tsserver.js

Yep, you’re right. I ran the yarn add command in the wrong directory 😅

It looks like that PR does indeed resolve this issue.

@vitosamson You were using using the TS 2.4 RC, correct?

This may be a duplicate of https://github.com/Microsoft/TypeScript/issues/16384