Angular 应用在 IE11 上发布后无法加载

Angular App Won't Load After Publishing On IE11

我目前正在 Angular 中开发一个带有 ASP.NET 后端的应用程序。我已将项目配置为在 IE11 中在本地正常工作(更新 polyfills、浏览器列表并添加 ES5 TsConfig 文件),但是当我通过 IIS 将其发布到服务器时,页面将无法加载并停留在“正在加载.. ."

为了测试发布,我尝试发布默认 Angular/ASP.NET 应用以获得相同的结果。

控制台显示四个错误:

SCRIPT1002: Syntax error
runtime.458556a34b891ea32398.js (1,1)

SCRIPT1002: Syntax error
polyfills-es5.7119ad0e4b3aeae98a0b.js (1,1)

SCRIPT1002: Syntax error
polyfills.4efda4a4618e08b621be.js (1,1)

SCRIPT1002: Syntax error
main.59969322f93fb24d6bee.js (1,1)

polyfills.ts

import 'classlist.js';
import 'web-animations-js';
import 'zone.js/dist/zone';

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
    <defaultDocument enabled="true">
      <files>
        <add value="ClientApp/dist/index.html" />
      </files>
    </defaultDocument>
  </system.webServer>

</configuration>

您的应用程序可能会在 IE11 中抛出错误,即使它在其他浏览器中运行良好。您的 Angular 应用程序无法运行的原因有很多,包括:

  • polyfills.ts 中缺少 polyfill。
  • 使用 IE11 不支持的 TypeScript 目标版本
  • 使用 TypeScript 目标版本导入 third-party 依赖项 IE11 不支持

参考这个:https://medium.com/better-programming/how-to-fix-your-angular-app-when-its-not-working-in-ie11-eb24cb6d9920

感谢@Deepak-MSFT 的回答,原来我没有在主机上安装 .NET Hosting Bundle。一旦我安装了它,网站就会按预期显示——除了一些与我在这里谈论的内容无关的问题。

对于那些好奇的人,我遇到了数据库连接字符串的问题,我发现服务器上托管了另一个项目并修改了它的连接字符串: data source=[database];initial catalog=[table];persist security info=True;user id=[user id];password=[password];MultipleActiveResultSets=True;App=EntityFramework

我还删除了我创建的 web.config 文件,因为它可能会妨碍发布期间生成的文件。