vs code cannot find module '@angular/core' or any other modules

前端 未结 30 1189
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 03:10

my project was generated with [Angular CLI] version 1.2.6.

I can compile the project and it works fine, but I always get error in vs code telling me cannot find mo

30条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 03:10

    I was facing this issue only while importing my own created components/services For those of you like me, for whom the accepted solution did not work, can try this:

    Add

    "baseUrl": "src"
    

    in your tsconfig.json. The reason is that visual code IDE is unable to resolve the base url so is unable to resolve path to imported components and gives error/warning.

    Whereas angular compiler takes src as baseurl by default so it is able to compile.

    NOTE:

    You need to restart VS Code IDE to make this change come into effect.

    EDIT:

    As mentioned in one of the comments, in some cases changing workspace version might also work. More details here: https://github.com/Microsoft/vscode/issues/34681#issuecomment-331306869

提交回复
热议问题