angularangular-universalangular-i18n

Angular Universal with i18n served locally: Failed to load module script


I'm trying to make my Angular universal app (version 15.1.0) run locally with i18n. I keep getting the following error though:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

It is being thrown for all JS files:

It is my understanding that the baseHref property is wrong, this is also what other posts here suggest. However, I can't spot what I'm doing wrong.

The relevant parts of my angular.json file (app is called "public"):

projects > public:

"i18n": {
    "sourceLocale": "en-US",
    "locales": {
      "de-DE": {
        "translation": "src/locale/messages.de.xlf",
        "baseHref": "/"
      }
    }
  },

projects > public > architect > build

"options": {
        "baseHref": "/",
        "localize": true,
        "outputPath": "dist/public/browser",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": ["src/styles.scss"],
        "scripts": [],
        "vendorChunk": true,
        "extractLicenses": false,
        "buildOptimizer": false,
        "sourceMap": true,
        "optimization": false,
        "namedChunks": true
      },

I also tried to replace all baseHref properties with an empty string, but it did not work either. My default language is en-US, the other de-DE. I'm trying to serve it in en-US locally.

What am I missing here?


Solution

  • The problem was that the sourceLocale in the i18n-node did not have any baseHref property set.

    So instead of

    "i18n": {
        "sourceLocale": "en-US"
    }
    

    it should rather be

    "i18n": {
        "sourceLocale": {
            "code": "en-US",
            "baseHref": "/"
        }
    }