Answer a question

I am having trouble with auto importing node_modules in angular, vsCode

Expected behaviour: When i start typing a name of an installed module in my angular typescript files, for instance "MatMenuM" or "HttpCl", a suggestion for an import should appear.

Current behaviour: The correct suggestion does not appear

matMenuModule suggestion fail

httpclient suggestion fail

My environment: Fresh angular project on windows 10 with newest(28.03.2022) versions of angular cli, node, typescript, vsCode, only two extensions, all up-to-date, and imported newest angular material.

angular version

tsconfig.json

tsconfig.app.json

extensions all up-to-date

angular.json 1

angular.json 2

package.json

import settings

I realize that this question has been asked a couple of times, but none of the answers solve my problem. Also the angular and ts versions might be different. I will link all related questions below. I also tried all of the suggested solutions:

I tried:

  • adding typeRoots in my tsconfig.json, as described here, all i got was this:

typeroot issue with cli

Also this github issue related to the same problem sais the issue should be fixed with the new ts version... which it isn't for me.

  • setting my preferred pathstyle for auto imports to relative, shortest, project-relative and non-relative

  • uninstalling angular, node, vsCode and ts and reinstalling it

  • removing all extensions

  • removing types: [] from my tsconfig.app.json

  • adding "node_modules/@angular/**/*.d.ts" to include in my tsconfig.app.json

Related questions: 1, 2, 3, 4, 5

Help will be much appreciated!

Edits: images not formatted correctly, spelling

Answers

Solved my problem:

VsCode does not autosuggest modules out of the box, even with older versions as far as i can tell. I was under the misconception that it did, since in my work project, suggestions work fine, however now i realize that was only because:

VsCode needs the module to be imported at least once (doesn't matter where) to suggest it everywhere.

So you have to import it once, then vsCode starts suggestions, which means only one time pain.

Still setting up a new project can be tedeous that way, i will use webstorm(suggests everything out of the box) as a setup IDE, then if my project as enough imports, i can still switch back to vsCode.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐