Object.assign() 在 IE11 中与 Angular2
Object.assign() in IE11 with Angular2
我知道这个问题已经被讨论了十亿次,但我在这里找到的 none 解决方案似乎对我的情况有所帮助。
这就是我的 polyfills.browser.ts 现在的样子:
import 'ie-shim';
import 'core-js/es7/reflect';
import 'reflect-metadata';
import 'zone.js/dist/zone';
如前所述,我尝试了不同的方法来解决这个问题。
我尝试添加所有默认未注释的导入:
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
我试过使用
import "core-js/client/shim";
还有
import 'mdn-polyfills/Object.assign';
和
import 'core-js';
所有这些都添加到 polyfills.browser.ts
的顶部
None 似乎有帮助,我不断收到 Object doesn't support 属性 or method 'assign' in IE11.
Object.assign
是 ES2015 并被 polyfill 覆盖:
import 'core-js/es6/object';
或者更广泛的 ES2015 polyfills:
import 'core-js/es6';
为什么最好在 Angular 应用程序中列出 ES2015 polyfill 而不是导入 core-js/es6
的原因是 core-js/es6/promise
polyfill 已经被 Zone.js 覆盖并且可能导致问题,.
如果这不起作用并且
Object doesn't support property or method 'assign'
发生错误,这意味着 polyfills
包未在浏览器中加载,或者在加载 polyfills
包之前评估了出现 Object.assign
的一段代码。
即使在 IE11 上使用 polyfill,我也有同样的问题,但不是每次都这样。问题是有时主脚本在 polyfill 之前加载,所以我在 webpack 配置中做了以下更改:
new CommonsChunkPlugin({
- name: 'polyfills',
- chunks: ['polyfills']
+ name: ['polyfills', 'main'].reverse(),
})
所以现在只有:
new CommonsChunkPlugin({
name: ['polyfills', 'main'].reverse(),
})
它似乎工作正常
我知道这个问题已经被讨论了十亿次,但我在这里找到的 none 解决方案似乎对我的情况有所帮助。
这就是我的 polyfills.browser.ts 现在的样子:
import 'ie-shim';
import 'core-js/es7/reflect';
import 'reflect-metadata';
import 'zone.js/dist/zone';
如前所述,我尝试了不同的方法来解决这个问题。
我尝试添加所有默认未注释的导入:
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
我试过使用
import "core-js/client/shim";
还有
import 'mdn-polyfills/Object.assign';
和
import 'core-js';
所有这些都添加到 polyfills.browser.ts
的顶部None 似乎有帮助,我不断收到 Object doesn't support 属性 or method 'assign' in IE11.
Object.assign
是 ES2015 并被 polyfill 覆盖:
import 'core-js/es6/object';
或者更广泛的 ES2015 polyfills:
import 'core-js/es6';
为什么最好在 Angular 应用程序中列出 ES2015 polyfill 而不是导入 core-js/es6
的原因是 core-js/es6/promise
polyfill 已经被 Zone.js 覆盖并且可能导致问题,.
如果这不起作用并且
Object doesn't support property or method 'assign'
发生错误,这意味着 polyfills
包未在浏览器中加载,或者在加载 polyfills
包之前评估了出现 Object.assign
的一段代码。
即使在 IE11 上使用 polyfill,我也有同样的问题,但不是每次都这样。问题是有时主脚本在 polyfill 之前加载,所以我在 webpack 配置中做了以下更改:
new CommonsChunkPlugin({
- name: 'polyfills',
- chunks: ['polyfills']
+ name: ['polyfills', 'main'].reverse(),
})
所以现在只有:
new CommonsChunkPlugin({
name: ['polyfills', 'main'].reverse(),
})
它似乎工作正常