【问题标题】:can't run ng serve in development mode无法在开发模式下运行 ng serve
【发布时间】:2021-09-02 07:13:51
【问题描述】:

我无法在开发模式下运行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 文件是这样的:

Terminal

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

Browser Inspect

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

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

我的 Chrome Angular 扩展警告我正在生产中运行,即使我不想这样做:

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 上的完全一样,我已经检查过了

更新: 迁移问题。 已运行 ng update @angular/cli --migrate-only --from=11.2.0 喜欢@BojanKojog 回答下面的问题。

【问题讨论】:

  • 显示你的 angular.json 文件。特别是“服务”部分。
  • @BojanKogoj,我已经更新了我的答案。
  • 更新有问题吗?尝试再次运行更新迁移ng update @angular/cli --migrate-only --from=11.2.0
  • 我认为我没有遇到问题!但是该命令解决了问题!你让我开心!
  • 我会把它发布为其他人找到的答案。

标签: javascript angular serve angular12


【解决方案1】:

重新运行更新迁移

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

Explanation

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多