Angular migration from 12 to 13 getting error : Cannot destructure property 'styles' of 'buildOptions.sourceMap' as it is undefined

Angular migration from 12 to 13 getting error : Cannot destructure property 'styles' of 'buildOptions.sourceMap' as it is undefined

我正在尝试将我的 angular 版本从 12 升级到 13 但出现错误 “发生未处理的异常:无法解构 'buildOptions.sourceMap' 的 属性 'styles',因为它未定义。”

我正在使用官方网站上提供的以下命令 npx @angular/cli@13 更新@angular/core@13 @angular/cli@13

请任何人帮助我

不幸的是,我无法在 angular.json 中找到添加 sourceMap 配置的有效位置。我所做的成功是通过创建一个新项目并将新 angular.json 的内容复制到我的旧项目来重置文件,然后在不匹配的地方更改项目名称。

该文件的示例版本如下:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": false
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "temp": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/temp",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "temp:build:production"
            },
            "development": {
              "browserTarget": "temp:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "temp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        }
      }
    }
  },
  "defaultProject": "temp"
}

我删除了软件包-lock.json,删除了 node_modules 文件夹并安装了 npm,它解决了这个问题。

如果有人在从 Angular 12 升级到 13 时遇到此问题,只需

replace this text '@ngx-env/builder' with '@angular-devkit/build-angular' in angular.json

此问题已在 2.0.1 版中修复。 如果您遇到同样的问题,请在 GitHub 回购 https://github.com/chihab/ngx-env/issues 上提出一个问题好吗?

PS: 我是包的作者:)