运行 ng serve 时找不到模块“@angular/compiler”

Posted

技术标签:

【中文标题】运行 ng serve 时找不到模块“@angular/compiler”【英文标题】:Cannot find module '@angular/compiler' when runnig ng serve 【发布时间】:2021-08-10 20:24:21 【问题描述】:

我已经更新了依赖项,从那时起,我在运行 ng serve 时收到此错误消息:

An unhandled exception occurred: Cannot find module '@angular/compiler'
Require stack:

我已经尝试过这个解决方案:Cannot find module '@angular/compiler' 但对我不起作用。 还删除了node_modules,再次签出项目。 我的依赖项有什么问题吗?或者我可以做些什么来让它再次运行?

这是我的 package.json:


"name": "wichteli",
"version": "0.0.0",
"scripts": 
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --disable-host-check",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"test:ci": "ng test --browsers ChromeHeadlessCI --code-coverage true --watch false",
"e2e:ci": "ng e2e --protractor-config=e2e/protractor-ci.conf.js",
"e2e": "ng e2e"
 ,
 "private": true,
 "devDependencies": 
 "@angular-devkit/build-angular": "~12.0.1",
 "@angular/compiler-cli": "~12.0.1",
 "@types/jasmine": "~3.7.4",
 "@types/node": "^15.6.0",
 "codelyzer": "^6.0.2",
 "jasmine-core": "~3.7.1",
 "jasmine-spec-reporter": "~7.0.0",
 "karma": "~6.3.2",
 "karma-chrome-launcher": "~3.1.0",
 "karma-coverage": "~2.0.3",
 "karma-coverage-istanbul-reporter": "^3.0.3",
 "karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "^1.6.0",
"karma-spec-reporter": "0.0.32",
"protractor": "~7.0.0",
"puppeteer": "^9.1.1",
"ts-node": "~9.1.1",
"tslint": "~6.1.0",
"typescript": "~4.2.4"


npm 版本输出:


  npm: '7.11.2',
  node: '12.18.1',
  v8: '7.8.279.23-node.38',
  uv: '1.38.0',
  zlib: '1.2.11',
  brotli: '1.0.7',
  ares: '1.16.0',
  modules: '72',
  nghttp2: '1.41.0',
  napi: '6',
  llhttp: '2.0.4',
  http_parser: '2.9.3',
  openssl: '1.1.1g',
  cldr: '37.0',
  icu: '67.1',
  tz: '2019c',
  unicode: '13.0'

ng --version 输出:

Angular CLI: 12.0.1
Node: 12.18.1
Package Manager: npm 7.11.2
OS: win32 x64

Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1200.1 (cli-only)
@angular-devkit/core         12.0.1 (cli-only)
@angular-devkit/schematics   12.0.1 (cli-only)
@schematics/angular          12.0.1 (cli-only)

【问题讨论】:

【参考方案1】:

我找到了解决方案。 首先,检查如何更新: https://update.angular.io/?l=2&v=12.0-12.0 从 12 更新到 13 在此之后,ng serve 或多或少地出现了一些错误消息,这些错误消息表明某些依赖项无法像 @angular/core 那样解决

npm install @angular/core

以及所有其他发现

在此之后,一切都恢复正常

【讨论】:

以上是关于运行 ng serve 时找不到模块“@angular/compiler”的主要内容,如果未能解决你的问题,请参考以下文章

运行 gulp app:serve rails 时找不到模块“require-dir”错误

运行“ng test”命令时找不到 JQuery

ng serve 命令需要在 Angular 项目中运行,但找不到项目定义

UnhandledPromiseRejectionWarning:错误:当我尝试运行我的代码时找不到模块'../database/db'

运行“排毒测试”时找不到模块@jest/reporters

运行不和谐机器人时找不到模块“节点:事件”错误