You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular Universal 15.1.0本地i18n运行报错:无法加载模块脚本

Angular Universal 15.1.0 本地启用i18n时MIME类型错误排查

我尝试让Angular Universal应用(版本15.1.0)在本地启用i18n运行,但持续出现以下错误:

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.

该错误针对所有JS文件抛出:

  • runtime.js
  • vendor.js
  • polyfills.js
  • main.js

我怀疑是baseHref属性配置错误,其他相关帖子也指向这个方向,但始终找不到问题所在。

以下是我的angular.json文件的相关配置(应用名为"public"):

projects > public 的i18n配置

"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
      },

我也曾尝试将所有baseHref属性替换为空字符串,但仍未解决问题。我的默认语言为en-US,另一种语言为de-DE,当前正尝试在本地运行en-US版本。

我忽略了什么?


内容的提问来源于stack exchange,提问作者user3255061

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 10:15:33