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

前端 未结 30 1120
佛祖请我去吃肉
佛祖请我去吃肉 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

    0 讨论(0)
  • 2020-12-23 03:11

    I solved this problem as follow:

    1. Open Visual studio code with your project.
    2. Terminal -> New Terminal.
    3. Write npm install.
    0 讨论(0)
  • 2020-12-23 03:11

    This worked for me.

     npm install --save-dev @angular-devkit/build-angular
    
    0 讨论(0)
  • 2020-12-23 03:12

    Occurs when cloning or opening existing projects in Visual Studio Code. In the integrated terminal run the command npm install

    0 讨论(0)
  • 2020-12-23 03:12

    Most likely npm package is missing. And sometimes npm install does not fix the problem.

    I have faced the same and I have solved this issue by deleting the node_modules folder and then npm install

    0 讨论(0)
  • 2020-12-23 03:12

    Do run

    npm install 
    

    it will work most of the cases

    0 讨论(0)
提交回复
热议问题