Typescript: VSCode "Import module" code action is no longer working after TypeScript 3 upgrade, tsserver throws error

Created on 9 Aug 2018  路  6Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.0.1, 3.1.0-dev.20180809


Search Terms: import code action

Expected behavior: VSCode "Import module" code action is no longer working after TypeScript 3 upgrade. Works fine in 2.9.x without needing to restart VSCode, and the error is in tsserver (per below).

Actual behavior:

On attempting to invoke a code action on an unknown symbol, which would normally show the "Import module" code action in TS2.9, the following error is logged:

Err 2421  [12:56:36.963] Exception on executing command {"seq":34,"type":"request","command":"getCodeFixes","arguments":{"file":"/Users/lindsey/Projects/frontend/src/index.tsx","startLine":89,"startOffset":3,"endLine":89,"endOffset":20,"errorCodes":[2304]}}:

    Debug Failure.

    Error: Debug Failure.
    at Object.assertDefined (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:1435:24)
    at getDefaultExportInfo (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105189:63)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105166:32
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105287:21
    at forEachExternalModule (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105300:21)
    at forEachExternalModuleToImportFrom (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105285:13)
    at getExportInfos (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105161:13)
    at getFixesInfoForNonUMDImport (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105147:57)
    at getFixesInfo (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:105085:19)
    at Object.getCodeActions (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:104870:28)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:103896:121
    at Object.flatMap (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:498:25)
    at Object.getFixes (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:103896:23)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:111747:35
    at Object.flatMap (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:498:25)
    at getCodeFixesAtPosition (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:111745:23)
    at Object.getCodeFixesAtPosition (/Users/lindsey/.vscode-insiders/extensions/jpoissonnier.vscode-styled-components-0.0.21/node_modules/typescript-template-language-service-decorator/lib/template-language-service-decorator.js:164:20)
    at IOSession.Session.getCodeFixes (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119339:64)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:118213:61)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119496:88
    at IOSession.Session.executeWithRequestId (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119487:28)
    at IOSession.Session.executeCommand (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119496:33)
    at IOSession.Session.onMessage (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119516:35)
    at Interface.<anonymous> (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:120770:27)
    at emitOne (events.js:116:13)
    at Interface.emit (events.js:211:7)
    at Interface._onLine (readline.js:282:10)
    at Interface._normalWrite (readline.js:424:12)
    at Socket.ondata (readline.js:141:10)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "esnext",
    "moduleResolution": "node",
    "target": "es5",
    "jsx": "react",
    "typeRoots": ["./typings"],
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "suppressImplicitAnyIndexErrors": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "lib": [
      "es6",
      "dom"
    ],
    "noImplicitThis": true,
    "allowJs": true,
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  },
  "include": [
    "./src/**/*",
    "node_modules/@types"
  ]
}

I'm not even sure where to start with trying to get more info on this, but I'm happy to provide any other configs if needed. As above this error doesn't happen at all in TS2.9, with no other changes to configs etc.

Bug Fixed

Most helpful comment

Ran into the bug while testing the debug build, fix is up at #26364.

All 6 comments

The error is happening because a default export somewhere in your program is confusing tsserver. (Since this is in the export-gathering phase it doesn't have much to do with the importing file and is probably happening every time.) If you could share the codebase we could look for it. Or if the number of export default in your program is low, you could test them out one at a time (commenting out the others) to see which one causes the failure. Or we could send you a build which prints more information about the failing export that you could send us.

thanks for the quick response! Happy to run a debug build, my email is [redacted]

Ran into the bug while testing the debug build, fix is up at #26364.

What does it mean that "a default export... is confusing tsserver" ?
That's not enough info to try to find the export that's surfacing this issue..

Can you provide any more details on the combination of things that result in this? .. I'm still on TS 2.9.1 because every published build since has had issues that broke my tooling... and this still doesn't seem to be resolved in the latest package.

@markthiessen This should be fixed already in typescript@next.

Thanks.. but I'd rather not use a nightly build in my project with so many issues recently with published releases. I'll try 3.1 when it's released..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Antony-Jones picture Antony-Jones  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

dlaberge picture dlaberge  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments