Docusaurus的IE失败:对象不支持属性或方法“分配”

时间:2019-09-14 16:11:38

标签: reactjs internet-explorer cross-browser docusaurus core-js

我们正在建立V2 Docusaurus网站:https://www.10studio.tech

我们刚刚意识到它在IE11中无法很好地工作。错误消息是:Object doesn't support property or method 'assign'

enter image description here

有些软件包具有IE兼容性,例如core-js,但我们不知道如何将其正确添加到Docusaurus v2中。

有人知道如何修改吗?

1 个答案:

答案 0 :(得分:1)

错误消息告诉您该对象没有assign functionassign是一个function,您正在使用的浏览器显然不支持它,因此您需要polyfill。一个很好的例子是:

if (!Object.assign) {
  Object.defineProperty(Object, 'assign', {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function(target) {
      'use strict';
      if (target === undefined || target === null) {
        throw new TypeError('Cannot convert first argument to object');
      }

      var to = Object(target);
      for (var i = 1; i < arguments.length; i++) {
        var nextSource = arguments[i];
        if (nextSource === undefined || nextSource === null) {
          continue;
        }
        nextSource = Object(nextSource);

        var keysArray = Object.keys(Object(nextSource));
        for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
          var nextKey = keysArray[nextIndex];
          var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
          if (desc !== undefined && desc.enumerable) {
            to[nextKey] = nextSource[nextKey];
          }
        }
      }
      return to;
    }
  });
}

可在此处找到:https://gist.github.com/spiralx/68cf40d7010d829340cb

但是,即使这可以解决您抱怨的问题,也很有可能还会发生其他问题。您可能还需要填充其他内容,您可能想看看BabelJS才能实现这一目标。