Angular 8 + IE 11:遗漏了一些 polyfill
Angular 8 + IE 11: Some polyfills are missed
我们需要让 Angular 8 和 IE 11 一起工作。
我们使用 target=es5,并且 ng serve 创建了 pollyfills-es5.js,其中包含所需的 array-includes polyfill,但是在控制台中出现错误:ERROR TypeError: Object doesn't support 属性 或方法 'includes'。其他代码工作正常,一些组件显示在屏幕上。
tsconfig.json
{
...
"compilerOptions": {
...
"target": "es2015",
"lib": ["es2018", "dom"],
"module": "esnext"
}
}
tsconfig.es5.js开
{
"extends": "./src/tsconfig.app.json",
"compilerOptions": {
"target": "es5"
}
}
angular.json
...
"build":{
...
"configurations":{
"es5": {
"tsConfig": "./tsconfig.es5.json"
}
}
...
},
"serve":{
...
"configurations":{
"es5": {
"browserTarget": "frontend:build:es5"
}
}
...
}
浏览器列表:最后 1 chrome 版本,IE 11
开始我们使用的代码:ng serve --live-reload=false --configuration=es5
结果 index.html 我们有
<script src="runtime.js" defer></script>
<script src="polyfills-es5.js" nomodule defer></script>
<script src="polyfills.js" defer></script>
<script src="styles.js" defer></script>
<script src="scripts.js" defer></script>
<script src="vendor.js" defer></script>
<script src="main.js" defer></script></body>
但在控制台中我们有:错误类型错误:对象不支持属性或方法'includes'
angular-cli 仅将它需要的 IE11 polyfill 添加到 polyfills-es5
。所以在这个文件中你只能找到使 angular 工作的 polyfill。 Angular 在它的源代码中没有使用 Array.includes
,所以如果你想在你的 polyfill 中使用它,你必须将它添加到你自己的 polyfill.ts 文件中。
import 'core-js/modules/es.array.includes'
这将在 polyfills.js
而不是 polyfills-es5.js
中结束。您可以找到更多信息 here
对我来说,在 polyfill.ts
中添加以下行在 Angular 10
中起作用
import 'core-js/es7/array';
我们需要让 Angular 8 和 IE 11 一起工作。
我们使用 target=es5,并且 ng serve 创建了 pollyfills-es5.js,其中包含所需的 array-includes polyfill,但是在控制台中出现错误:ERROR TypeError: Object doesn't support 属性 或方法 'includes'。其他代码工作正常,一些组件显示在屏幕上。
tsconfig.json
{
...
"compilerOptions": {
...
"target": "es2015",
"lib": ["es2018", "dom"],
"module": "esnext"
}
}
tsconfig.es5.js开
{
"extends": "./src/tsconfig.app.json",
"compilerOptions": {
"target": "es5"
}
}
angular.json
...
"build":{
...
"configurations":{
"es5": {
"tsConfig": "./tsconfig.es5.json"
}
}
...
},
"serve":{
...
"configurations":{
"es5": {
"browserTarget": "frontend:build:es5"
}
}
...
}
浏览器列表:最后 1 chrome 版本,IE 11
开始我们使用的代码:ng serve --live-reload=false --configuration=es5
结果 index.html 我们有
<script src="runtime.js" defer></script>
<script src="polyfills-es5.js" nomodule defer></script>
<script src="polyfills.js" defer></script>
<script src="styles.js" defer></script>
<script src="scripts.js" defer></script>
<script src="vendor.js" defer></script>
<script src="main.js" defer></script></body>
但在控制台中我们有:错误类型错误:对象不支持属性或方法'includes'
angular-cli 仅将它需要的 IE11 polyfill 添加到 polyfills-es5
。所以在这个文件中你只能找到使 angular 工作的 polyfill。 Angular 在它的源代码中没有使用 Array.includes
,所以如果你想在你的 polyfill 中使用它,你必须将它添加到你自己的 polyfill.ts 文件中。
import 'core-js/modules/es.array.includes'
这将在 polyfills.js
而不是 polyfills-es5.js
中结束。您可以找到更多信息 here
对我来说,在 polyfill.ts
中添加以下行在 Angular 10
import 'core-js/es7/array';