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

Created on 17 Jun 2017  路  17Comments  路  Source: microsoft/TypeScript

_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_

Duplicate VS Code Tracked

Most helpful comment

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

All 17 comments

_From @pocesar on June 16, 2017 20:0_

getting this as well, I need to close the file and reopen to be able to get intellisense back

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

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

@mjbvz thanks for moving this to the correct repo.

I'm using 2.4, not RC:

> yarn list | grep typescript
鈹溾攢 [email protected]

Looks like it's at least related to that issue, judging by the stack trace in that one. I'm only seeing this when starting a new import above an existing one.

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

@odensc as an emergency feature, that worked well, thanks

Confirm @mjbvz that this is the same issue #16384

Closing as a duplicate of #16384. On schedule for TS 2.4.1 which we plan to pick up for the final VScode 1.14 release

The other issue and PR only references dynamic imports - this is happening with normal ES6 imports too.

@odensc it is that we are too aggressively consider import in expression contact as import call even though it is not ( it is only importCall if it follows with "(" ) .... I am going to update the original bug with this as well.

This bug is still present when installing TS from that PR branch.

@vitosamson Here is what I did to try repo the issue and verify against the PR branch that it doesn't:

  1. insert import { foo } from './foo';
  2. add a new line above..... type import... Previously it causes assert failure but now it will give a parsing error

let me know if I miss anything

Here's what I'm seeing:

  1. yarn add 'microsoft/typescript#master-fixIncrementalParsingWithDynamicImport'
  2. restart VS Code
  3. follow the repro steps I outlined in the original issue

Code shows the same error: [ts] Cannot find name 'impor'.

tsserver.log shows:

Info 179  request: {"seq":64,"type":"request","command":"completionEntryDetails","arguments":{"file":"/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts","line":1,"offset":2,"entryNames":["import"]}}
Err 180   Exception on executing command {"seq":64,"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 181  response: {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":64,"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 182  request: {"seq":65,"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 183  65::change: async elapsed time (in milliseconds) 0.1840
Info 184  request: {"seq":66,"type":"request","command":"geterr","arguments":{"delay":0,"files":["/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/index.ts"]}}
Perf 185  66::geterr: async elapsed time (in milliseconds) 0.1992
Err 186   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 187  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"}]}}

Seems to be the same behavior as before.

@vitosamson I don't think your tsserver.js is from the branch (I am unsuccessfully try to install with yarn 馃槥 because file-path is too long. I will try on my mac machine ) but from looking at the line number here

at parseUpdateExpression (/Users/samson/Desktop/dev/typescript/tsserver-crash-repro/node_modules/typescript/lib/tsserver.js:17313:22)

it doesn't corresponding to inside parseUpdateExpression function in the tsserver.js built from the branch.... let me know if that is the case (another way to confirm is that tsserver.js from that branch has version 2.5 (if you would want to search for the version #)

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 Thanks for confirming!! 馃嵃

The PR fixes the issue for me too, thanks @yuit!

Quick fix for VSCode is to click and change the version of Typescript to one that's not bundled in the app - locally installed in a project, or as a global package.

Was this page helpful?
0 / 5 - 0 ratings