Typescript: auto import not working properly

Created on 18 Dec 2019  ·  10Comments  ·  Source: microsoft/TypeScript

Issue Type: Bug

auto import is not working in the new udpate, it was working in the previous build

VS Code version: Code 1.41.0 (9579eda04fdb3a9bba2750f15193e5fafe16b959, 2019-12-11T17:59:52.065Z)
OS version: Windows_NT ia32 10.0.18363

here is a short video on that
https://drive.google.com/file/d/1inQ1yZGLSfxeXmGLcDl81nEsATyTrjik/view

image


System Info

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (8 x 1992)|
|GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled|
|Load (avg)|undefined|
|Memory (System)|15.90GB (5.95GB free)|
|Process Argv||
|Screen Reader|no|
|VM|67%|

Extensions (5)

Extension|Author (truncated)|Version
---|---|---
vscode-apollo|apo|1.12.2
gitlens|eam|10.2.0
prettier-vscode|esb|3.16.1
python|ms-|2019.11.50794
vscode-import-cost|wix|2.12.0


Needs More Info

Most helpful comment

@IllusionMH i have created a video on that. please have a look
https://drive.google.com/file/d/1inQ1yZGLSfxeXmGLcDl81nEsATyTrjik/view
i am not getting any suggestion when pressing Ctrl+space, also Go to definition is not working

All 10 comments

/needsMoreInfo

Please provide more in info about language, your configuration, code that causes problemts etc.

If you are using TS/JS and expecting to see packages that aren't in your package.json it intentional https://github.com/microsoft/TypeScript/pull/32517 and duplicate of https://github.com/microsoft/TypeScript/issues/35560

Thanks for creating this issue! We figured it's missing some basic information or in some other way doesn't follow our issue reporting guidelines. Please take the time to review these and update the issue.

Happy Coding!

I have this issue as well. I try to import a type, which a package supplies, but it doesn't appear in the suggestions. The package is defined in the package.json as devDependency.

TypeScript 3.7.3 (Also tried Nightly with same result) on Ubuntu 18.04.

I've noticed this not working on multiple occasions with different packages. Some packages work, others don't. Not sure if there is anything with caching going on here.

@IllusionMH i have created a video on that. please have a look
https://drive.google.com/file/d/1inQ1yZGLSfxeXmGLcDl81nEsATyTrjik/view
i am not getting any suggestion when pressing Ctrl+space, also Go to definition is not working

For me it's a bit different:

  • local imports work fine
  • import from a dependency will not be suggested.
  • Once I manually write the import statement, I can go to definition just fine
  • Once I manually write the import statement for at least one type, I can even auto-import other types/methods from that dependency.
  • However, after removing that import statement again, auto-import suggestions are gone again.

I had the same problem since the update to VSC 1.41.0. In my case, it seams that the latest Typescript version (3.7.3) is causing the import problems.

I resolved it by using an anterior TS version. I used the Typescript Workspace version (mine is 3.5.3) instead of VS Code's version (3.7.3). You can see/set it at the bottom-right of the VSC editor.

Hope it can help.

@SantoJambit looks it functions as designed in your case if "import from a dependency will not be suggested." is about dependency that is not in your package.json since auto-imports from packages in 3.7 only show suggestions for direct dependencies (see https://github.com/microsoft/TypeScript/pull/32517)
If this package is in your package.json but not in suggestions - please create new issue.

As soon as you manually add import to your file - you add this module to your project tree and it will be treated as usually with auto-import functionality.


@Tahir500 do you see "Initializing JS/TS language features" in the status bar after commenting out import and requesting suggestion? Looks like TS takes too much time to process updated project tree or hangs/crashes in process.

To understand what goes wrong more info about project structure will be useful (or link to repo if it's in open access).
It will be also useful to know if there are nay errors in DevTools and TS Server logs _(please note that tsserver.log contains path to files on your disk and you might need to redact it before sharing)_

/cc @andrewbranch

@IllusionMH i have created a video on that. please have a look
https://drive.google.com/file/d/1inQ1yZGLSfxeXmGLcDl81nEsATyTrjik/view
i am not getting any suggestion when pressing Ctrl+space, also Go to definition is not working

Oh, I found delete node_modules folder, and reinstall node_modules later, it working, you can try it

update:
it just working once, reopen workspace, it not working

update again:
I delete node_modules/@types folder, it working

@Tahir500 Please share repo steps and code as text in addition to the videos

@IllusionMH I am talking about direct dependencies. But I just tried using an older TS version with the same result, so maybe this is a vscode issue and not a typescript issue.

Edit: It seems my issue is @types vs bundled types, as described here: https://github.com/microsoft/vscode/issues/88015

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manekinekko picture manekinekko  ·  3Comments

weswigham picture weswigham  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

uber5001 picture uber5001  ·  3Comments

Roam-Cooper picture Roam-Cooper  ·  3Comments