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"):
"i18n": {
"sourceLocale": "en-US",
"locales": {
"de-DE": {
"translation": "src/locale/messages.de.xlf",
"baseHref": "/"
}
}
},
"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?
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": "/"
}
}