tldr;
在独立服务器上运行时,用target=es2015和差异加载构建应用程序在IE11中工作。
用target=es5 构建它,在IE11中不起作用
示例可复制代码:https://github.com/thegreatanon/prism-ie-crash/tree/master
详细信息
我正在构建的“角8”应用程序需要与IE11兼容。为了确保这一点,我需要在开发期间不时地对它进行测试。
现在在角8中引入了差异加载,当浏览器列表中启用了es2015和ES5文件时,它将构建IE11和IE11文件。当获取这些生成的文件并在独立服务器上运行它们时,它将在IE11中运行良好。但这太麻烦了。
使用ng服务只会创建ES2015版本,因此在IE中不起作用。
然后创建一个不同的配置,将compilationOptions中的compilationOptions设置为es5,并将其运行为ng serve - configuration es5。
在使用这种方法时,一旦单击导航中的项(触发模块的延迟加载),IE控制台中就会出现以下错误。
SCRIPT1006: Expected ')'
ERROR Error: Uncaught (in promise): ChunkLoadError: Loading chunk example-example-module failed.

查看错误发生的行,我看到以下内容:
function ChangeDetection(detection = true, properties) {显然,该函数中的默认参数是罪魁祸首,因为ES5不支持此功能。

如您所见,代码来自角包/变更检测,这包括在内,因为我使用的是角包/棱镜。
外部代码似乎只是以-is形式包含,并没有被转移到ES5中。
当我只是为ES5构建并在我的独立服务器上运行它时,我也会遇到同样的错误。因此,它可能与ng serve命令本身没有任何关系。
因为当使用角度上的差异加载设置时,ES5构建确实有效,似乎有一些魔术发生了吗?
有人能告诉我如何将这些外部资源转移到ES5吗?
tsconfig
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": ["node_modules/@types"],
"lib": ["dom", "es2018"],
"strict": true,
"paths": {
"@mylib/angular-components": ["lib"],
"@mylib/angular-components/*": ["lib/*"]
}
},
"exclude": ["out", "node_modules", "dist", "lib"],
"angularCompilerOptions": {
"preserveWhitespaces": false,
"fullTemplateTypeCheck": true
}
}browserlist
"browserslist": [
"last 5 Chrome version",
"last 5 Safari version",
"last 5 Firefox version",
"last 5 Edge version",
"last 5 iOS version",
"last 5 ChromeAndroid version",
"IE 11",
"> 1%"
]发布于 2019-08-28 13:44:13
在浏览器列表文件中,您必须删除not以支持not IE 9-11 # For IE 9-11 support, remove 'not'.到IE 9-11 # For IE 9-11 support, remove 'not'.行中的IE11
有关更多信息,请参阅本文的差分加载 https://blog.angularindepth.com/embrace-yourself-angular-8-is-coming-1bf187c8f0bf段落
https://stackoverflow.com/questions/57693741
复制相似问题