angular: 10.1.0 i18n compilation error: Localized bundle generation failed: Cannot read property 'value' of undefined

🐞 bug report

Affected Package

Angular 10.1.0

Is this a regression?

Yes, no issues with 10.0.x (all of them)

Description

Upgrading our project to 10.1.0

ng update @angular/core @angular/cli --force

No issues, upgrade goes through without issues.

However, when doing a production build I get this error:

Localized bundle generation failed: Cannot read property 'value' of undefined

I am using i18n with 3 languages.

🌍 Your Environment

Angular Version:


Angular CLI: 10.0.8
Node: 12.13.1
OS: darwin x64

Angular: 10.1.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker
Ivy Workspace: <error>

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1000.8
@angular-devkit/build-angular      0.1000.8
@angular-devkit/build-optimizer    0.1000.8
@angular-devkit/build-webpack      0.1000.8
@angular-devkit/core               10.0.8
@angular-devkit/schematics         10.0.8
@angular/cdk                       10.0.1
@angular/cli                       10.0.8
@angular/fire                      6.0.2
@angular/material                  10.0.1
@angular/material-moment-adapter   10.0.1
@ngtools/webpack                   10.0.8
@schematics/angular                9.1.6
@schematics/update                 0.1000.8
rxjs                               6.5.5
typescript                         3.9.6
webpack                            4.43.0

🌍 angular.json


{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "selfservice": {
      "i18n": {
        "locales": {
          "da": "src/locale/messages.da.xlf",
          "sv": "src/locale/messages.sv.xlf",
          "en": "src/locale/messages.en.xlf"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "style": "sass"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/robots.txt",
              "src/favicon.png",
              "src/assets",
              "src/browserconfig.xml",
              "src/manifest.json",
              {
                "glob": "**/*",
                "input": "./assets",
                "output": "assets/"
              }
            ],
            "styles": [
              "./node_modules/material-icons/iconfont/material-icons.scss",
              "src/styles/index.scss"
            ],
            "scripts": [
              "./node_modules/file-saver/dist/FileSaver.min.js",
              "src/assets/js/modernizr.js"
            ]
          },
          "configurations": {


            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "localize": [
                "da", "sv", "en"
              ],
              "optimization": true,
              "outputHashing": "bundles",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": true,
              "buildOptimizer": true,
              "serviceWorker": true,
              "outputPath": "dist"
            },
            "da": {
              "aot": true,
              "localize": [
                "da"
              ],
              "outputPath": "dist"
            },
            "sv": {
              "aot": true,
              "localize": [
                "sv"
              ],
              "outputPath": "dist"
            },
            "en": {
              "aot": true,
              "localize": [
                "en"
              ],
              "outputPath": "dist"
            },
            "integration": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.integration.ts"
                }
              ],
              "aot": true,
              "localize": [
                "en"
              ],
              "outputPath": "dist"
            },


            "staging": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                }
              ],
              "localize": [
                "da", "sv", "en"
              ],
              "optimization": true,
              "outputHashing": "bundles",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": true,
              "buildOptimizer": true,
              "serviceWorker": true,
              "outputPath": "dist"
            },
           
            "test": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ],
              "localize": [
                "da", "sv", "en"
              ],
              "optimization": true,
              "outputHashing": "bundles",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": true,
              "buildOptimizer": true,
              "serviceWorker": true,
              "outputPath": "dist"
            }
  
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "selfservice:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "selfservice:build:production"
            },
            "integration": {
              "browserTarget": "selfservice:build:integration"
            },
            "da": {
              "browserTarget": "selfservice:build:da"
            },
            "sv": {
              "browserTarget": "selfservice:build:sv"
            },
            "en": {
              "browserTarget": "selfservice:build:en"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "selfservice: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.sass"
            ],
            "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/**"
            ]
          }
        }
      }
    },
    "selfservice-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "selfservice:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "selfservice:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "selfservice",
  "cli": {
    "analytics": "e39974f2-c043-437e-ad6b-c5bb38cf1079"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

Could it be that this is an issue with CLI 10.0, but not the to be released CLI 10.1?

i had the same error using cli 10. after upgrading cli to 10.1 the problem has gone!

I used this to fix:

ng update @angular-devkit/build-angular

^^

"@angular-devkit/build-angular": "^0.1001.2"   (version workinjg on 22-09-20)

I had the same issue after upgrading to 10.1. I figured out that “outdated” dependencies showed up in “ng --version”. I fixed them manually in package.xml. Now the output of “ng --version” looks like this

Angular CLI: 10.1.0

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1001.0
@angular-devkit/build-angular      0.1001.0
@angular-devkit/build-ng-packagr   0.1001.0
@angular-devkit/build-optimizer    0.1001.0
@angular-devkit/build-webpack      0.1001.0
@angular-devkit/core               10.1.0
@angular-devkit/schematics         10.1.0
@angular/cdk                       10.2.0
@angular/material                  10.2.0
@ngtools/webpack                   10.1.0
@schematics/angular                10.1.0
@schematics/update                 0.1001.0
ng-packagr                         10.1.0
rxjs                               6.5.5
typescript                         3.9.7
webpack                            4.44.1

and --localize runs fine.

Phew! Thanks for the update.

Further I had a look through the @angular/localize code base and (assuming your are targeting es2015) the most likely place this exception is being thrown is in unwrapMessagePartsFromTemplateLiteral() (https://github.com/angular/angular/blob/master/packages/localize/src/tools/src/source_file_utils.ts#L163). I would propose adding some logging in there to see but I am not sure if the CLI is running the translation in a separate thread/process that would swallow the logging or not.

Could it be that this is an issue with CLI 10.0, but not the to be released CLI 10.1?

One thing you could try is building the application with localization turned off - this should output a main.js file in the dist folder, which you could then try translating manually with something like:

node_modules/.bin/localize-translate -r dist -s **/*.js -t src/locale/messages.da.xlf -o translated