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

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

    I was facing this issue in my angular 5 application today. And the fix which helped me, was simple. I added "moduleResolution": "node" to the compilerOptions in the tsconfig.json file. My complete tsconfig.json file content is below.

    {
      "compileOnSave": false,  
      "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "typeRoots": [
          "node_modules/@types"
        ],
        "lib": [
          "es2017",
          "dom"
        ]
      }
    }
    

    The moduleResolution specify module resolution strategy. The value of this settings can be node or classic. You may read more about this here.

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

    The fix for me was to import the entire project. For those who have this problem in 2019 please check if you have imported the entire project not a part of the project.

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

    If you did what I (foolishly) did... Which was drag and drop a component folder into my project then you'll probably be able to solve it by doing what I did to fix it.

    Explanation: Basically, by some means Angualar CLI must tell InteliJ what @angular means. If you just plop the file in your project without using the Angular CLI i.e. ng g componentName --module=app.module then Angular CLI doesn't know to update this reference so IntelliJ has no idea what it is.

    Approach: Trigger the Angular CLI to update references of @angular. I currently know only one way to do this...

    Implementation: Add a new component at the same level as the component your having issues with. ng g tempComponent --module=app.module This should force the Angular CLI to run and update these references in the project. Now just delete the tempComponent you just created and don't forget to remove any reference to it in app.module.

    Hope this helps someone else out.

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

    In my case, when i upgrade vs project to angular 10, I had this errors.

    Angular cli creates tsconfig.json, tsconfig.base.json and tsconfig.app.json when i delete tsconfig.json and rename tsconfig.base.json to tsconfig.ts all things will Ok. you must also change extends inside tsconfig.app.json to tsconfig.json

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

    I had the same problem. I resolved it by clearing npm cache which is at "C:\Users\Administrator\AppData\Roaming\npm-cache"

    Or you can simply run:

    npm cache clean --force
    

    and then close vscode, and then open your folder again.

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

    for Visual Studio -->

        Seems like you don't have `node_modules` directory in your project folder.
         
        Execute this command where `package.json` file is located:
        
         npm install 
    
    0 讨论(0)
提交回复
热议问题