Vscode: Auto-expansion of `from` path for ES6 imports

Created on 9 Jul 2018  路  21Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.25.0
  • OS Version: All

Steps to Reproduce:

  1. Create a file with import {isObject} from 'lodash-es'.
  2. Save some other, seemingly unrelated files.
  3. The from portion of the import is expanded in every file it occurs in to a relative import path, such as:
import {isObject} from '../../../../Library/Caches/typescript/2.9/node_modules/@types/lodash-es'

Obviously this is just a minor nuisance when you've got a couple files, but when you hit 4-5 thousand files being updated for no apparent reason on a semi-regular basis, this is a major problem.

Does this issue occur when all extensions are disabled?: Yes

needs more info

Most helpful comment

This also affects the auto-import hint. See the attached picture for examples
screen shot 2018-07-09 at 5 22 29 pm

All 21 comments

I'm experiencing similar issues in all of my Angular projects (all created with Angular CLI, if that's any help).

Another weird thing, I cannot quite reproduce: Sometimes, after opening a new folder in VS Code, it just starts opening TS files and modifying their imports without them being in any way related to the file I'm currently working on. At one point, ~80 files were opened and modified.

Please try upgrading your workspace to use typescript@next by following these instructions. Do you still see the issue?

@mjbvz it isn't reproducing on the TS 3.0.0-dev.20180707. TS v2.9.2 is affected.

I have upgrade to typescript 3.0.0-dev.20180707; I'll report back if I encounter the issue (which was quite frequent).

If you have not heard from me by next week this time, it'll be safe to presume the issue has not exhibited with this version of typescript for us.

Thanks

Unfortunately the issue continues to exhibit with typescript@next (after having installed it with yarn add -D typescript@next and restarting vscode) by performing the following steps:

  1. Have files that import from lodash-es
  2. Have an import named abc/abc.js (the 'react' style of module import)
  3. Have another file that has import something from 'abc'

If you rename abc.js in the file explorer with right-click, then all the lodash-es imports get rewritten to relative paths.

This also affects the auto-import hint. See the attached picture for examples
screen shot 2018-07-09 at 5 22 29 pm

My whole team is seeing this issue as well. Auto-import was working really well up until ~2 weeks ago.

@brianmhunt Did you also run the TypeScript: Select typescript version command to change your workspace to use TS 3.0 as well?

VS Code insiders now also includes TS 3.0 by default. I can't repo this issue on 3.0 following your steps

I tried the insiders version of VSCode with TS 3.0 and this was fixed for me.

VS Code - Insiders with TS 3.0 also fixed the issue for me, including the auto-import hint.

Selecting "Use Workspace Version" from the Typescript Status Bar fixed the issue for me that I'm experiencing in an Angular application. Though, previous versions of VS Code worked with 2.9.2.

@samtsai I had to make the same changes to fix the issue. But the downside is, auto update for file/directory renaming/moving stopped working. TypeScript >= 2.9 is required for auto update to work :disappointed:

I can confirm this still occurs, with a few debugging notes below.

Here's the output from some commands:

$ yarn list | grep typescript
鈹溾攢 [email protected]
$ cat .tsserver.js
{
   "typescript.tsdk": "./node_modules/typescript/lib"
}

There are no extensions of interest, and all the typescript settings are defaults.

Note that I could not find a TypeScript: Select typescript version option, nor a Typescript Status Bar (hence no Use Workspace Version option).

Please advise of any further information that might assist diagnosis & prescription.

@brianmhunt what version of VS Code are you using? Have you tried to reproduce this with Code - Insiders?

@Curdflappers VS Code 1.25.1. I don't know what Code - Insiders is. :)

Visual Studio Code - Insiders is the daily update version of VS Code, so it includes the most recent stable build, and you can update daily. For me, changing from regular VS Code to Insiders fixed this issue, though it was likely the typescript version. You can download Insiders here: https://code.visualstudio.com/insiders/

You should be able to copy and paste workspace settings, keyboard shortcuts, etc since they're JSON

I'm closing this issue as fixed in VS Code insiders when using TS 3.0. If you still see this issue when using typescript 3.0, please open a new issue and I'll take a look

I'm still having this issue with VSC 1.25.1 on a pure Javascript React project

@mjbvz Just upgraded to VS Code 1.26. When using TypeScript 3.0.1, I'm not getting quick fixes for missing imports. If I switch back to TypeScript 2.9.2 (which Angular is using), I'm getting the quick fixes but the expansion issue remains.

Update 3: Opened an issue in the AWS Amplify repo.
Update 2: Okay, finally figured it out. The issue is caused by https://github.com/aws-amplify/amplify-js.
Update 1: Here's the error log. Any idea what's going on?

'getCodeFixes' request failed with error.Error processing request.
Debug Failure. Error: Debug Failure.
    at Object.assertDefined (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:1435:24)
    at getDefaultExportInfo (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105189:63)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105166:32
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105287:21
    at forEachExternalModule (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105300:21)
    at forEachExternalModuleToImportFrom (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105285:13)
    at getExportInfos (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105161:13)
    at getFixesInfoForNonUMDImport (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105147:57)
    at getFixesInfo (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105085:19)
    at Object.getCodeActions (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:104870:28)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:103896:121
    at Object.flatMap (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:498:25)
    at Object.getFixes (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:103896:23)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:111747:35
    at Object.flatMap (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:498:25)
    at Object.getCodeFixesAtPosition (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:111745:23)
    at IOSession.Session.getCodeFixes (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119339:64)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:118213:61)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119496:88
    at IOSession.Session.executeWithRequestId (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119487:28)
    at IOSession.Session.executeCommand (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119496:33)
    at IOSession.Session.onMessage (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119516:35)
    at Interface. (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\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)'getCodeFixes' request failed with error.Error processing request. Debug Failure.Error: Debug Failure.
    at Object.assertDefined (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:1435:24)
    at getDefaultExportInfo (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105189:63)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105166:32
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105287:21
    at forEachExternalModule (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105300:21)
    at forEachExternalModuleToImportFrom (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105285:13)
    at getExportInfos (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105161:13)
    at getFixesInfoForNonUMDImport (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105147:57)
    at getFixesInfo (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105085:19)
    at Object.getCodeActions (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:104870:28)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:103896:121
    at Object.flatMap (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:498:25)
    at Object.getFixes (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:103896:23)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:111747:35
    at Object.flatMap (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:498:25)
    at Object.getCodeFixesAtPosition (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:111745:23)
    at IOSession.Session.getCodeFixes (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119339:64)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:118213:61)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119496:88
    at IOSession.Session.executeWithRequestId (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119487:28)
    at IOSession.Session.executeCommand (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119496:33)
    at IOSession.Session.onMessage (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119516:35)
    at Interface. (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\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)'getCodeFixes' request failed with error.Error processing request. Debug Failure.Error: Debug Failure.
    at Object.assertDefined (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:1435:24)
    at getDefaultExportInfo (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105189:63)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105166:32
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105287:21
    at forEachExternalModule (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105300:21)
    at forEachExternalModuleToImportFrom (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105285:13)
    at getExportInfos (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105161:13)
    at getFixesInfoForNonUMDImport (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105147:57)
    at getFixesInfo (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:105085:19)
    at Object.getCodeActions (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:104870:28)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:103896:121
    at Object.flatMap (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:498:25)
    at Object.getFixes (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:103896:23)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:111747:35
    at Object.flatMap (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:498:25)
    at Object.getCodeFixesAtPosition (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:111745:23)
    at IOSession.Session.getCodeFixes (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119339:64)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:118213:61)
    at c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119496:88
    at IOSession.Session.executeWithRequestId (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119487:28)
    at IOSession.Session.executeCommand (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119496:33)
    at IOSession.Session.onMessage (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:119516:35)
    at Interface. (c:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\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)

@tuhinkarmakar Unrelated to the original issue. Likely https://github.com/Microsoft/TypeScript/issues/26333 Try upgrading your workspace to TypeScript@next to see if the issue is fixed

@mjbvz Yes, you are right. The problem I reported is unrelated to the original issue. Like you said, TypeScript 3.0 did fix the original issue. But after I upgraded to version 3.0, I faced the issue mentioned above. I just wanted to leave a note here that upgrading to version 3.0 has its own problems.

P.S. Though I am not sure, I think issue #57017 and #57164 are related to the issue I am facing.

Was this page helpful?
0 / 5 - 0 ratings