Vs cannot find the module '@ angular / core' or any other modules

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

I can compile the project and it works fine, but I always get an error in the code telling me cannot find the module '@ angular / core' cannot find the module '@ angular / router' cannot find the module .....

screenshot screenshot

I added the contents of my tsconfig.json file, it really upset me, spending 2 hours to find out what was wrong, I also uninstalled and reinstalled the code vs it does not work.

here is my environment specification:

@angular/cli: 1.2.6
node: 6.9.1
os: win32 x64
@angular/animations: 4.3.4
@angular/common: 4.3.4
@angular/compiler: 4.3.4
@angular/core: 4.3.4
@angular/forms: 4.3.4
@angular/http: 4.3.4
@angular/platform-browser: 4.3.4
@angular/platform-browser-dynamic: 4.3.4
@angular/router: 4.3.4
@angular/cli: 1.2.6
@angular/compiler-cli: 4.3.4
@angular/language-service: 4.3.4

os: Microsoft vs 10 enterprise

project root folder

.angular-cli.json
.editorconfig
.gitignore
.vscode
e2e
karma.conf.js
node_modules
package.json
protractor.conf.js
README.md
src
tsconfig.json
tslint.json

node_module folder

-@angular
--animations
--cli
--common
--compiler
--compiler-cli
--core
---@angular
---bundles
---core.d.ts
---core.metadata.json
---package.json
---public_api.d.ts
---README.md
---src
---testing
---testing.d.ts
---testing.metadata.json
--forms
--http
--language-service
--platform-browser
--platform-browser-dynamic
--router
--tsc-wrapped
@ng-bootstrap
@ngtools
-@types
--jasmine
--jasminewd2
--node
--q
--selenium-webdriver

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}
+48
source share
20 answers

, , , , JavaScript TypeScript IntelliSense - . https://marketplace.visualstudio.com/items?itemName=sourcegraph.javascript-typescript

, -, , , , , vs, .

+2

/. , , , :

"baseUrl": "src"

tsconfig.json. , IDE URL, /.

, src baseurl , .

:

VS Code IDE, .

:

, . : https://github.com/Microsoft/vscode/issues/34681#issuecomment-331306869

+72

, node_modules :

npm install

.

+29

,

+14

npm install

, visual studio.

+10

:

npm audit fix --force

:

npm install --save @ng-bootstrap/ng-bootstrap

@ng-bootstrap/ng-bootstrap .

+4

. , npm, "C:\Users\Administrator\AppData\Roaming\npm-cache"

:

npm cache clean --force

vscode .

+4

angular 5 angular 5 . , , . "moduleResolution": "node" compilerOptions tsconfig.json. tsconfig.json tsconfig.json .

{
  "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"
    ]
  }
}

moduleResolution . node classic. .

+2

angular-cli package.json @angular/cli

$ npm uninstall angular-cli
$ npm install @angular/cli --save-dev

, .

+1

, , , "nodes_modules" . , github throu git.

0

Visual Studio. npm install

0

:

  1. Visual Studio .
  2. → .
  3. npm install.
0

. , @angular/core, .

import { Component } from '@angular/core';
Hide result
0

. , 2019 , , , , .

0

. , .

-1

, CLI, , . CLI 1 CLI 4. - CLI. nvm, . CLI .

nvm @: Windows. MAC Linux.

-2

, , , VS Code, .

-2

npm install 

-2

, :

 npm i @anglar/core,
 npm i @angular/common,
 npm i @angular/http,
 npm i @angular/router

, .

-3

All Articles