【问题标题】:Angular 9 build Generating ES5 bundles for differential loading... An unhandled exception occurred :Angular 9 build 为差异加载生成 ES5 包...发生未处理的异常:
【发布时间】:2020-06-21 13:49:54
【问题描述】:

昨天我将我的项目升级到了 Angular v9。运行 ng build 时出现以下错误。

为差异加载生成 ES5 包... 发生未处理的异常: C:\workspace\project\ui\pages-pages-module-es2015.js:属性左侧 ForInStatement 期望节点是一个类型 ["VariableDeclaration","LVal"] 但得到了 null 见 "C:\Users\sayoo\AppData\Local\Temp\ng-BaceZi\angular-errors.log" 对于 更多细节。

请在以下文件中找到: 包.json

{
  "name": "ui",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "start:ar": "ng serve --configuration=ar-IQ",
    "build": "ng build",
    "build:ar": "ng build --configuration=ar-IQ",
    "test": "ng test",
    "test:coverage": "ng test --code-coverage",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "int-extract": "ng xi18n --output-path src/locale",
    "postinstall": "ngcc"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.7",
    "@angular/animations": "^9.0.5",
    "@angular/common": "~9.0.5",
    "@angular/compiler": "~9.0.5",
    "@angular/core": "~9.0.5",
    "@angular/forms": "~9.0.5",
    "@angular/localize": "~9.0.5",
    "@angular/platform-browser": "~9.0.5",
    "@angular/platform-browser-dynamic": "~9.0.5",
    "@angular/router": "~9.0.5",
    "@fullcalendar/angular": "^4.2.1",
    "@fullcalendar/bootstrap": "^4.2.0",
    "@fullcalendar/core": "^4.2.0",
    "@fullcalendar/daygrid": "^4.2.0",
    "@fullcalendar/interaction": "^4.2.0",
    "@fullcalendar/timegrid": "^4.2.0",
    "@iplab/ngx-file-upload": "^1.4.0",
    "@ng-bootstrap/ng-bootstrap": "^5.1.0",
    "@ng-select/ng-select": "^3.0.3",
    "angular-archwizard": "^4.0.0",
    "animate.css": "^3.7.2",
    "apexcharts": "^3.8.3",
    "bootstrap": "^4.3.1",
    "chart.js": "^2.8.0",
    "chartist": "^0.11.3",
    "core-js": "^2.5.4",
    "karma-viewport": "^1.0.5",
    "metismenujs": "^1.0.3",
    "ng-apexcharts": "^1.0.5",
    "ng-click-outside": "^4.0.0",
    "ng2-charts": "^2.3.0",
    "ng2-search-filter": "^0.5.1",
    "ng5-slider": "^1.2.4",
    "ngx-bootstrap": "^5.1.0",
    "ngx-chartist": "^1.0.3",
    "ngx-color-picker": "^8.1.0",
    "ngx-drag-drop": "^2.0.0",
    "ngx-editor": "^4.1.0",
    "ngx-image-cropper": "^1.4.1",
    "ngx-lightbox": "^2.0.1",
    "ngx-mask": "^8.0.3",
    "ngx-ui-switch": "^8.1.0",
    "rxjs": "^6.5.2",
    "smooth-scrollbar": "^8.3.1",
    "sweetalert2": "^8.16.3",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.5",
    "@angular/cli": "~9.0.5",
    "@angular/compiler-cli": "~9.0.5",
    "@angular/language-service": "~9.0.5",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.7.5"
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ui": {
      "i18n": {
        "locales": {
          "ar-IQ": {
            "translation": "src/locale/messages.ar.xlf",
            "baseHref": ""
          }
        }
      },
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/ui",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/assets/scss/bootstrap.scss",
              "src/assets/scss/app.scss",
              "src/assets/scss/icons.scss"
            ],
            "scripts": [],
            "es5BrowserSupport": true
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "ar-IQ": {
              "outputPath": "dist/ui-ar-iq/",
              "i18nFile": "src/locale/messages.ar.xlf",
              "i18nLocale": "ar-IQ",
              "i18nMissingTranslation": "error"
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ui:build",
            "port": 4200,
            "host": "falcon.me",
            "disableHostCheck": true
          },
          "configurations": {
            "production": {
              "browserTarget": "ui:build:production"
            },
            "ar-IQ": {
              "browserTarget": "ui:build:ar-IQ"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ui: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",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/assets/scss/bootstrap.scss",
              "src/assets/scss/app.scss",
              "src/assets/scss/icons.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "ui:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "ui:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "ui"
}

pages.routing.module

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  { path: '', redirectTo: '/apps/obstacles', pathMatch: 'full' },
  { path: 'apps', loadChildren: () => import('./apps/apps.module').then(m => m.AppsModule) }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class PagesRoutingModule { }

【问题讨论】:

  • 听起来 AOT 遇到了一个未解决的问题,angular-errors.log 有什么帮助吗?
  • 在问题中添加了错误日志。
  • 你有什么想法吗?
  • 什么是 pages-pages-module?那里的任何内容或您可能正在使用的模板for...in 或for....of?
  • 该模块只有基本元数据及其路由模块

标签: angular


【解决方案1】:

找到上述问题的解决方案。 修复步骤 1.运行过时的npm。 2. 从软件包列表中将红色的软件包更新为想要的版本。

【讨论】:

  • 这对我有用,当时我已经失去了解决它的希望。
  • 很好听。
  • 您可以运行“npm update”将所有包从当前更新为想要的。
  • 这可能是问题的原因,但它并没有解决我的问题。
【解决方案2】:

临时解决方案: @angular-devkit/build-angular 发生了变化,更新了差分负载。要在 Angular 项目中解决此问题,请将 tsconfig.json 中的目标值从“es2015”更改为“es5”:

{ “compileOnSave”:假, “编译器选项”:{ "baseUrl": "./", "outDir": "./dist/out-tsc", “源地图”:是的, “声明”:错误, “模块”:“esnext”, "moduleResolution": "节点", “emitDecoratorMetadata”:真, “experimentalDecorators”:是的, “importHelpers”:是的, “目标”:“es5”, “类型根”:[ “node_modules/@types” ], “库”:[ "es2018", “dom” ] } }

【讨论】:

  • 通过进行此更改,差异加载将被禁用。所以这可以用作临时解决方案。
  • 感谢您验证解决方案。如果您觉得有帮助,请点赞。
【解决方案3】:

我遇到了同样的问题,并通过删除使用 svg.js@2.7.1 的包来解决!!!从你的发现来看,这个错误是由 svg.js@2.7.1 的停产版本引起的!!! 查看您的应用程序内部有一个使用它的包并将其删除!

(注意:对于我的写作中可能出现的错误,我很抱歉,我是巴西人,我必须使用谷歌翻译来写这个)

【讨论】:

  • 谢谢哥们。没有找到任何带有 svg.js@2.7.1 的包。我使用 npm outdated 命令检查了过时的包,并将过时的包更新为所需的版本。现在它的工作。感谢您的回答,否则我不会这样做。
  • 您好,我注意到您使用的是 apexcharts,并且 svg.js@2.7.1 是对 apexcharts 的依赖,执行更新时问题已解决!恭喜!
猜你喜欢
  • 1970-01-01
  • 2020-10-23
  • 1970-01-01
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
相关资源
最近更新 更多