升级Angular和项目后找不到编译器ngcc模块

JSm*_*ith 18 npm angular-cli angular

我刚刚将Angular cli和我的一个项目从7.0.7升级到7.1.0。

我关注了这篇文章以及@Francesco Borzi的回答。

现在我尝试使用以下命令运行我的项目:

ng serve --proxy-config proxy.conf.json
Run Code Online (Sandbox Code Playgroud)

并收到此消息

找不到模块'@ angular / compiler-cli / ngcc'错误:找不到

模块'@ angular / compiler-cli / ngcc'

at Function.Module._resolveFilename (internal/modules/cjs/loader.js:649:15)

at Function.Module._load (internal/modules/cjs/loader.js:575:25)

at Module.require (internal/modules/cjs/loader.js:705:19)

at require (internal/modules/cjs/helpers.js:14:16)

at Object.<anonymous> (/Users/path/myproject/node_modules/@ngtools/webpack/src/ngcc_processor.js:10:16)

at Module._compile (internal/modules/cjs/loader.js:799:30)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)

at Module.load (internal/modules/cjs/loader.js:666:32)

at tryModuleLoad (internal/modules/cjs/loader.js:606:12)

at Function.Module._load (internal/modules/cjs/loader.js:598:3)

at Module.require (internal/modules/cjs/loader.js:705:19)

at require (internal/modules/cjs/helpers.js:14:16)

at Object.<anonymous> (/Users/path/myproject/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:23:26)

at Module._compile (internal/modules/cjs/loader.js:799:30)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)

at Module.load (internal/modules/cjs/loader.js:666:32)
Run Code Online (Sandbox Code Playgroud)

这是我的 package.json

{
  "name": "myproject",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.0.0",
    "@angular/cdk": "7.3.7",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/material": "^7.3.7",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "angular": "^1.7.8",
    "bootstrap": "^4.3.1",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jquery": "1.9.1",
    "ngx-gallery": "^5.9.1",
    "popper.js": "^2.0.0-next.4",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.800.1",
    "@angular/cli": "^8.0.1",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/language-service": "~7.0.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 11

在您的package.json文件中,将devDependencies中的@ angular / cli版本更改为:

"@angular/cli": "7.1.0"
Run Code Online (Sandbox Code Playgroud)

您的项目和devDependency之间版本不匹配。您可能已经使用过npm audit fix --force或类似的自动更新命令,该命令可能已经更新了“ package.json”文件中的devDependencies。

您也可以在devDependencies中使用angular cli版本7.3.5。只要确保开发版本和devDependencies中提到的版本兼容即可。请注意,本地角度/ cli版本在这里并不重要。

更新:进行更改后,删除“ package-lock.json”并删除“节点模块”文件夹。npm install再次运行以安装模块。


小智 5

我遇到了同样的错误,并通过更新@ angular / cli global解决了此问题。喜欢:

npm uninstall -g @angular/cli
npm install -g @angular/cli
Run Code Online (Sandbox Code Playgroud)

然后尝试创建新应用,并将一些依赖项从package.json文件复制到当前项目,因为npm install不会安装最新版本的软件包。然后

npm install
Run Code Online (Sandbox Code Playgroud)

这解决了我的问题,但后来我找到了这个答案:更新角度


Mar*_*ouk 5

所有这些都对我不起作用,我试图从 Angular 7 升级到 Angular 8,这是适合我的工作解决方案:

  1. npm 过时了。
  2. npm 更新。
  3. npm install -g npm-check。
  4. npm-check -u --skip-unused。
  5. 使用 npm-check 升级所有过时的包,除了 sass 包。
  6. npm 更新。
  7. 如果您的应用程序中有 ViewChild,请务必将它们编辑为@ViewChild(<name>, {static: true}).