8

我无法ng serve在开发模式下运行。

我已将 Angular v11 升级到 v12。从那以后,我一直在编译延迟,并且似乎没有启用开发模式。

我总是收到这个警告:

****************************************************************************************
This is a simple server for use in testing or debugging Angular applications locally.
It hasn't been reviewed for security issues.

DON'T USE IT FOR PRODUCTION!
****************************************************************************************

我的 Lazy Chunk 文件是这样的:

终端

由于正在浏览器上设置编译文件,因此需要花费大量时间来调试任何内容。

浏览器检查

我已经检查了我的 enviroment.ts 变量并设置为:

export const environment = {
  production: false,
  api: 'http://127.0.0.1:8000'
};

我的 Angular Extension for Chrome 警告我正在生产中运行,即使我不想:

We detected an application built with production configuration. Angular DevTools only supports development builds.

angular.json 上的 ng 服务部分

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "backoffice:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "backoffice:build:production"
            }
          }
        }

和 v11 上的完全一样,我已经检查过了

更新:迁移问题。像@BojanKojog ng update @angular/cli --migrate-only --from=11.2.0 一样运行,回答如下。

4

1 回答 1

5

重新运行更新迁移

ng update @angular/cli --migrate-only --from=11.2.0

解释

未使用 ng update 更新到 v12 的项目缺少重要的迁移,这些迁移将一些构建器选项切换为 v11 中的默认值。如果没有此迁移,构建器现在假定生产配置,因为默认值已更改为默认表示生产构建。在 ng update @angular/cli 中运行的自动迁移会将受影响的选项设置为其先前的默认值,以便项目继续表现相同。然而,如果没有这种迁移,构建会被配置为生产并启用相应的优化,从而使开发构建变得非常缓慢。

请使用 ng update @angular/cli --migrate-only --from=11.2.0 应用迁移,或者在 v11 上使用 ng update @angular/core @angular/cli 进行更新。

于 2021-06-17T13:44:49.007 回答