Angular 10.2 构建:本地化包生成失败:无法读取未定义的属性“值”

Posted

技术标签:

【中文标题】Angular 10.2 构建:本地化包生成失败:无法读取未定义的属性“值”【英文标题】:Angular 10.2 build: Localized bundle generation failed: Cannot read property 'value' of undefined 【发布时间】:2021-05-14 03:37:04 【问题描述】:

我有一个基于 Angular 10.0.11 的项目。

我使用npm update 将项目更新到10.2,但这导致在尝试构建时出现多个Unable to fully load [...] for source-map flattening: Circular source file mapping dependency -errors

我解决了:

rm -rf node_modules package-lock.json
npm install

但我仍然无法构建。在该过程结束时,我收到此错误:

[...]
Generating ES5 bundles for differential loading...
ES5 bundle generation complete.
Generating localized bundles...
Localized bundle generation failed: Cannot read property 'value' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ed-app@0.0.0 build-prod-da: `ng build --prod --configuration=production-da`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ed-app@0.0.0 build-prod-da script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jde/.npm/_logs/2021-02-10T12_06_55_122Z-debug.log

我不知道这里出了什么问题。根据《Angular 更新指南》,从 10.0 更新到 10.2 应该是小菜一碟。

这是日志文件的内容:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'run', 'build-prod-da' ]
2 info using npm@6.14.11
3 info using node@v14.15.4
4 verbose run-script [ 'prebuild-prod-da', 'build-prod-da', 'postbuild-prod-da' ]
5 info lifecycle ed-app@0.0.0~prebuild-prod-da: ed-app@0.0.0
6 verbose lifecycle ed-app@0.0.0~prebuild-prod-da: unsafe-perm in lifecycle true
7 verbose lifecycle ed-app@0.0.0~prebuild-prod-da: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/jde/edApp2Angular10Prerender2/node_modules/.bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/opt/gradle/gradle-6.8.1/bin:/var/lib/snapd/snap/bin:/home/jde/flutter_projects/flutter/bin:/home/jde/.local/bin:/home/jde/bin:/home/jde/flutter_projects/flutter/bin:/opt/gradle/gradle-6.8.1/bin:/home/jde/flutter_projects/flutter/bin:/home/jde/.local/bin:/home/jde/bin:/home/jde/flutter_projects/flutter/bin:/opt/gradle/gradle-6.8.1/bin
8 verbose lifecycle ed-app@0.0.0~prebuild-prod-da: CWD: /home/jde/edApp2Angular10Prerender2
9 silly lifecycle ed-app@0.0.0~prebuild-prod-da: Args: [ '-c', 'npm run before-build' ]
10 silly lifecycle ed-app@0.0.0~prebuild-prod-da: Returned: code: 0  signal: null
11 info lifecycle ed-app@0.0.0~build-prod-da: ed-app@0.0.0
12 verbose lifecycle ed-app@0.0.0~build-prod-da: unsafe-perm in lifecycle true
13 verbose lifecycle ed-app@0.0.0~build-prod-da: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/jde/edApp2Angular10Prerender2/node_modules/.bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/opt/gradle/gradle-6.8.1/bin:/var/lib/snapd/snap/bin:/home/jde/flutter_projects/flutter/bin:/home/jde/.local/bin:/home/jde/bin:/home/jde/flutter_projects/flutter/bin:/opt/gradle/gradle-6.8.1/bin:/home/jde/flutter_projects/flutter/bin:/home/jde/.local/bin:/home/jde/bin:/home/jde/flutter_projects/flutter/bin:/opt/gradle/gradle-6.8.1/bin
14 verbose lifecycle ed-app@0.0.0~build-prod-da: CWD: /home/jde/edApp2Angular10Prerender2
15 silly lifecycle ed-app@0.0.0~build-prod-da: Args: [ '-c', 'ng build --prod --configuration=production-da' ]
16 silly lifecycle ed-app@0.0.0~build-prod-da: Returned: code: 1  signal: null
17 info lifecycle ed-app@0.0.0~build-prod-da: Failed to exec build-prod-da script
18 verbose stack Error: ed-app@0.0.0 build-prod-da: `ng build --prod --configuration=production-da`
18 verbose stack Exit status 1
18 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
18 verbose stack     at EventEmitter.emit (events.js:315:20)
18 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
18 verbose stack     at ChildProcess.emit (events.js:315:20)
18 verbose stack     at maybeClose (internal/child_process.js:1048:16)
18 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
19 verbose pkgid ed-app@0.0.0
20 verbose cwd /home/jde/edApp2Angular10Prerender2
21 verbose Linux 5.10.8-200.fc33.x86_64
22 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "run" "build-prod-da"
23 verbose node v14.15.4
24 verbose npm  v6.14.11
25 error code ELIFECYCLE
26 error errno 1
27 error ed-app@0.0.0 build-prod-da: `ng build --prod --configuration=production-da`
27 error Exit status 1
28 error Failed at the ed-app@0.0.0 build-prod-da script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]

angular.json


  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": 
    "edApp": 
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "ed",
      "schematics": 
        "@schematics/angular:component": 
          "styleext": "scss"
        
      ,
      "i18n": 
        "sourceLocale":"en",
        "locales": 
          "da":"src/i18n/messages.da.xlf"
        
      ,
      "architect": 
        "build": 
          "builder": "@angular-devkit/build-angular:browser",
          "options": 
            "outputPath": "dist/edApp",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/manifest.json",
              "src/apple-touch-icon.png",
              "src/browserconfig.xml",
              "src/favicon-16x16.png",
              "src/favicon-32x32.png",
              "src/mstile-150x150.png",
              "src/safari-pinned-tab.svg"
            ],
            "scripts": [ 
              "src/scripts/parallax.js"
            ],
            "styles": [
              
                "input": "./node_modules/bootstrap/dist/css/bootstrap.css"
              ,
              "./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
              "src/styles.scss",
              "./node_modules/cropperjs/src/css/cropper.scss"
            ],
            "allowedCommonJsDependencies": [
              "crypto-js",
              "element-resize-detector",
              "batch-processor",
              "lodash"
            ]
          ,
          "configurations": 
            "da": 
              "aot": true,
              "outputPath": "dist/da",
              "baseHref": "/da/",
              "localize":["da"]
            ,
            "en": 
              "aot": true,
              "outputPath": "dist/en",
              "baseHref": "/en/",
              "localize":["en"]
          
            ,
            "production-da-test": 
              "index": 
                "input": "src/index.test.da.html",
                "output": "index.html"
              ,
              "outputPath": "dist-test",
              "localize":["da"],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true
            ,
            "production-da": 
              "index": 
                "input": "src/index.prod.da.html",
                "output": "index.html"
              ,
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "outputPath": "dist-prod/",
              "localize":["da"],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true
            ,
            "production-en": 
              "index": 
                "input": "src/index.prod.en.html",
                "output": "index.html"
              ,
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "outputPath": "dist-prod/",
              "baseHref": "/en/",
              "localize":["en"],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true
            ,
            "production": 
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true
            
          
        ,
        "serve": 
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": 
            "browserTarget": "edApp:build",
            "proxyConfig": "proxy.conf.json",
            "disableHostCheck": true,
            "port":4300
          ,
          "configurations": 
            "production-da": 
              "browserTarget": "edApp:build:production-da"
            ,
            "production-en": 
              "browserTarget": "edApp:build:production-en"
            ,
            "production": 
              "browserTarget": "edApp:build:production"
            ,
            "en": 
              "browserTarget": "edApp:build:en"
            ,
            "da": 
              "browserTarget": "edApp:build:da"
            
          
        ,
        "extract-i18n": 
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": 
            "browserTarget": "edApp:build"
          
        ,
        "test": 
          "builder": "@angular-devkit/build-angular:karma",
          "options": 
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/manifest.json"
            ]
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          
        
      
    ,
    "edApp-e2e": 
      "root": "e2e/",
      "projectType": "application",
      "architect": 
        "e2e": 
          "builder": "@angular-devkit/build-angular:protractor",
          "options": 
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "edApp:serve"
          ,
          "configurations": 
            "production": 
              "devServerTarget": "edApp:serve:production"
            
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          
        
      
    
  ,
  "defaultProject": "edApp"

package.json


  "name": "ed-app",
  "version": "0.0.0",
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "before-build": "node prebuild.js",
    "extract-i18n": "ng xi18n --output-path i18n && xliffmerge --profile xliffmerge.json da en",
    "serve-da": "ng serve -o --configuration=da",
    "serve-en": "ng serve -o --configuration=en",
    "serve-da-home": "ng serve -o --configuration=da --host 0.0.0.0",
    "serve-en-home": "ng serve -o --configuration=en --host 0.0.0.0",
    "build-da": "ng build --configuration=da",
    "build-en": "ng build --configuration=en",
    "build-prod-da-test": "ng build --prod --configuration=production-da-test",
    "prebuild-prod-da": "npm run before-build",
    "prebuild-test-da": "npm run before-build",
    "build-test-da": "ng build --prod --configuration=production-da-test --crossOrigin=anonymous",
    "build-prod-da": "ng build --prod --configuration=production-da",
    "build-prod-en": "ng build --prod --configuration=production-en",
    "build-all": "for lang in da en; do npm run build-$lang; done",
    "build-prod-all": "for lang in da en; do npm run build-prod-$lang; done"
  ,
  "browser": 
    "crypto": false
  ,
  "private": true,
  "dependencies": 
    "@angular/animations": "^10.2.4",
    "@angular/cdk": "^10.2.7",
    "@angular/common": "^10.2.4",
    "@angular/compiler": "^10.2.4",
    "@angular/core": "^10.2.4",
    "@angular/forms": "^10.2.4",
    "@angular/localize": "^10.2.4",
    "@angular/platform-browser": "^10.2.4",
    "@angular/platform-browser-dynamic": "^10.2.4",
    "@angular/pwa": "^0.1000.8",
    "@angular/router": "^10.2.4",
    "@angular/service-worker": "^10.2.4",
    "@ckeditor/ckeditor5-angular": "^1.2.3",
    "@clampy-js/ngx-clampy": "^8.0.1",
    "@fortawesome/angular-fontawesome": "^0.7.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.34",
    "@fortawesome/free-regular-svg-icons": "^5.15.2",
    "@fortawesome/free-solid-svg-icons": "^5.15.2",
    "@it-era/ngx-safe-pipes": "^0.2.1",
    "@ng-select/ng-select": "^5.1.0",
    "@ngx-pwa/local-storage": "^10.1.0",
    "@ngx-translate/core": "^13.0.0",
    "angular-file": "^3.4.0",
    "blueimp-canvas-to-blob": "^3.28.0",
    "body-scroll-lock": "^3.1.5",
    "bootstrap": "^4.6.0",
    "canvas-to-blob": "^1.0.0",
    "core-js": "^3.8.3",
    "cropperjs": "^1.5.9",
    "crypto-js": "^4.0.0",
    "element-resize-detector": "^1.2.1",
    "hammerjs": "^2.0.8",
    "heic-convert": "^1.2.4",
    "heic2any": "0.0.3",
    "lodash-es": "^4.17.20",
    "moment": "^2.29.1",
    "ng-sidebar": "^9.4.2",
    "ngx-bootstrap": "^5.6.2",
    "ngx-moment": "^5.0.0",
    "ngx-smart-modal": "^7.4.1",
    "ngx-spinner": "^10.0.1",
    "rxjs": "^6.6.3",
    "rxjs-tslint": "^0.1.8",
    "survey-angular": "^1.8.29",
    "zone.js": "^0.11.3"
  ,
  "devDependencies": 
    "@angular-devkit/build-angular": "^0.1000.8",
    "@angular/cli": "^10.2.2",
    "@angular/compiler-cli": "^10.2.4",
    "@angular/language-service": "^10.2.4",
    "@types/jasmine": "^3.6.3",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^14.14.25",
    "codelyzer": "^6.0.1",
    "inquirer": "^7.3.3",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.2",
    "karma": "^5.2.3",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~4.0.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "protractor": "^7.0.0",
    "replace-in-file": "^6.2.0",
    "ts-node": "^8.10.2",
    "tslint": "~6.1.3",
    "typescript": "^3.9.8"
  

【问题讨论】:

【参考方案1】:

您可以在tsconfig.ts 中简单地将targetes2015 更改为es5

它会修复错误。

【讨论】:

我有一个 Angular 11 项目,目标是 es2015,没有任何问题,所以我无法验证这一点。您是否有更多信息说明为什么这是一个解决方案? 您是否在该项目中使用本地化,如果使用,您是否在其上使用 includes 之类的功能? 这是由 Angular 团队更改编译器逻辑引起的,并且此错误再次出现在 v13.0.0 上。这就是我想出这个解决方案的原因 我正在使用 Angulars i18n 进行本地化...我不确定将 es2015 更改为 es5 是否有任何陷阱。我将不得不阅读更多有关它的信息。不过谢谢你的解释。【参考方案2】:

我最终升级到 Angular 11

然后我重新安装了所有软件包以重新开始。在那之后,还有一些包不是完全最新的,所以我用 ncu (npm-check-updates) 来解决这个问题......

rm -rf node_modules package-lock.json
npm install
ncu -u
npm install

然后问题就消失了。我怀疑这可能是由于某种包版本不匹配或 Angular 10.2.4 的问题。

【讨论】:

以上是关于Angular 10.2 构建:本地化包生成失败:无法读取未定义的属性“值”的主要内容,如果未能解决你的问题,请参考以下文章

Angular CLI 9 (Ivy) 使用本地库 (mono-repo) 构建应用程序失败

Xcode 10.2、Swift 5、Command compileSwift 在使用 Release Scheme 构建程序时失败

安装ArcGIS 10.2 Server 出现图示问题

Maven 包有效,但 Intellij 的构建失败

angular 生成浏览器应用程序包时是不是可以运行 lint? [复制]

Angular 8 - Headless Chrome 运行两次,第二次失败