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

IT技术 reactjs internet-explorer cross-browser docusaurus core-js
2021-05-26 03:25:22

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

我们刚刚意识到它在 IE 中效果不佳,例如 IE11。错误信息是:Object doesn't support property or method 'assign'

在此处输入图片说明

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

有谁知道如何修改这个?

1个回答

错误消息告诉您该对象没有assign function. assignfunction这显然不是在你谈论的浏览器所支持,所以你需要填充工具它。一个很好的例子是:

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

但是,即使这可以解决您所抱怨的问题,也很可能会出现其他问题。您可能还需要 polyfill 其他一些东西,您可能需要查看BabelJS以实现这一点。