最近在使用angular-cli时,出现了”无法找到模块’@angular-devkit/core'”的错误

错误内容 (Error message)

$ ng --version
Error: Cannot find module '@angular-devkit/core'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/homahi/workspace/rxjs/node_modules/@angular-devkit/schematics/src/tree/virtual.js:10:16)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

不知不觉之间出现了错误。

在使用yarn时也出现了警告。

warning "@schematics/angular@0.1.16" has unmet peer dependency "@angular-devkit/core@0.0.28".
warning "@angular-devkit/schematics@0.0.51" has unmet peer dependency "@angular-devkit/core@0.0.28".

解决方案

升级Angular-Cli版本

$ npm uninstall -g @angular-cli
$ npm cache verify
$ npm install -g @angular/cli@latest

康复了

% ng --version                                                                                                                                                                    ~/workspace homahi-2

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 1.6.5
Node: 8.1.2
OS: darwin x64
Angular: 
...

bannerAds