ng serve 在 Angular 升级到 Angular 13 后无法正常工作

我使用此处提供的角度更新指南 https://angular.io/guide/update-to-latest-version 将我的角度项目从 12 升级到 13,没有任何问题。但是,当使用“ng serve --open”命令在我的本地机器(mac)上运行项目时,它会提示浏览器下载窗口,而不是运行项目。我注意到没有编译错误并且 ng build 成功。我尝试删除并重新安装节点模块,但问题仍然存在。这是我的 package.json 文件。任何线索都受到高度赞赏。谢谢。

{
  "name": "dashboard-new11",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^13.1.3",
    "@angular/common": "^13.1.3",
    "@angular/compiler": "^13.1.3",
    "@angular/compiler-cli": "^13.1.3",
    "@angular/core": "^13.1.3",
    "@angular/forms": "^13.1.3",
    "@angular/platform-browser": "^13.1.3",
    "@angular/platform-browser-dynamic": "^13.1.3",
    "@angular/platform-server": "^13.1.3",
    "@angular/router": "^13.1.3",
    "@types/file-saver": "^2.0.1",
    "@types/jest": "^26.0.4",
    "angular-webstorage-service": "^1.0.2",
    "angular2-toaster": "^11.0.1",
    "core-js": "^2.4.1",
    "ngx-bootstrap": "^7.1.2",
    "ngx-webstorage-service": "^4.1.0",
    "node": "^14.15.1",
    "pako": "^1.0.11",
    "rxjs": "^6.6.7",
    "rxjs-compat": "^6.5.2",
    "tslib": "^2.0.0",
    "typescript": "4.5.4",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.1.4",
    "@angular/cli": "^13.1.4",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "file-saver": "^2.0.5",
    "karma": "~6.3.9",
    "karma-chrome-launcher": "~3.1.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "ng-autosize": "^1.1.0",
    "protractor": "~7.0.0",
    "schematics-scss-migrate": "^1.3.14",
    "ts-node": "~2.0.0",
    "tslint": "~6.1.3"
  }
}

这是启动日志

✔ Browser application bundle generation complete.

Initial Chunk Files   | Names         |  Raw Size
vendor.js             | vendor        |   4.58 MB | 
main.js               | main          |   1.88 MB | 
polyfills.js          | polyfills     | 386.86 kB | 
styles.css, styles.js | styles        | 260.59 kB | 
runtime.js            | runtime       |   6.86 kB | 

                      | Initial Total |   7.10 MB

Build at: 2022-01-20T07:38:36.218Z - Hash: e641c46fc4de7304 - Time: 17292ms

Warning: /Users/TSC/Desktop/Watson360/Backups/Advisor360-UI-Angular13/client/src/app/shared/app.http.service.ts depends on 'pako'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning: /Users/TSC/Desktop/Watson360/Backups/Advisor360-UI-Angular13/client/src/app/shared/app.messenger.service.ts depends on 'rxjs/Rx'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

✔ Compiled successfully.
stack overflow ng serve not working after angular upgrading to Angular 13
原文答案

答案:

作者头像

升级到Angular 13之后,我只是遇到了同样的问题。

请验证构建选项部分中的Angular.json文件中的内容。在那里您应该找到以下内容:

"index": "src/index.html",

几年前,我曾经将其更改为“ index.aspx”,因为我在SharePoint中进行了大型企业应用程序,但是现在这使我拥有您描述的行为。