0

I've installed the angular localize package, and it's working locally, but when I try to build to production I got this error:

Localized bundle generation failed: Cannot read properties of undefined (reading 'file')

I'm using the Angular: 10.2.5. If I run ng server the project builds and I can see the translation. I have more projects inside the same structure.


My angular.json file:

{
  "sport": {
    ...
    "i18n": {
      "sourceLocale": "de",
      "locales": {
        "en": "apps/sport/locale/messages.en.xlf"
      }
    },
    "architect": {
      "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
          ...
          "localize": true,
          "aot": true
        },
        "configurations": {
          "production": {
            "fileReplacements": [
              {
                "replace": "apps/sport/src/environments/environment.ts",
                "with": "apps/sport/src/environments/environment.prod.ts"
              }
            ],
            ...
            "sourceMap": true
          },
          "en": {
            "aot": true,
            "localize": ["en"]
          },
          "e2e": {
            "fileReplacements": [
              {
                "replace": "apps/sport/src/environments/environment.ts",
                "with": "apps/sport/src/environments/environment.e2e.ts"
              }
            ]
          }
        }
      },
      "serve": {
        "builder": "@angular-devkit/build-angular:dev-server",
        "options": {
          "browserTarget": "sport:build",
          "port": 4201
        },
        "configurations": {
          "production": {
            "browserTarget": "sport:build:production"
          },
          "en": {
            "browserTarget": "sport:build:en"
          }
        }
      },
      "extract-i18n": {
        "builder": "@angular-devkit/build-angular:extract-i18n",
        "options": {
          "browserTarget": "sport:build"
        }
      }
    }
  }
}
Stark
  • 65
  • 2
  • 9
  • I recommend to create a complete new project with only one app inside and starting to localize that. After a successful setup, I would start to work with multible apps. Always start with minimum complexitiy and increase it with every successfully change. – Daniel Michelfelder Nov 21 '22 at 20:55
  • Yeah, but it's a project from a company, I can't split the apps, unfortunately. – Stark Nov 22 '22 at 11:58
  • Try to make a running instance. For example you could create an complete new angular project. Then try to localize that. Then work with multible apps. Then compare it your solution. I think you have problems with your paths, because you use multible apps. Maybee you need to change your project structure. All should be inside the src - path. try this: src/apps/sport/.... src/apps/anotherApp/... or work with libraries. – Daniel Michelfelder Jan 13 '23 at 12:07
  • If you work with multible apps that must be combined on one solution, I recommend to google for "Micro Frontends". There are a some good solutions outside, to build "apps" independent of other apps. That would meke it possible to work with multible teams on your solution. – Daniel Michelfelder Jan 13 '23 at 12:13

0 Answers0