Docusaurus fails with IE: Object doesn't support property or method 'assign'

蓝咒 提交于 2019-12-07 20:14:51

问题


We are making a V2 Docusaurus website: https://www.10studio.tech.

We have just realized that it does not work well in IE, for instance, IE11. The error message is: Object doesn't support property or method 'assign'.

There are some packages to provide with IE compatibility such as core-js, but we don't know how to properly add it to Docusaurus v2.

Does anyone know how to amend this?


回答1:


The error message is telling you that object doesn't have an assign function. assign is a function which apparently is not supported in the browser you are speaking about, so you need to polyfill it. A good example is:

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;
    }
  });
}

which can be found here: https://gist.github.com/spiralx/68cf40d7010d829340cb

However, even though this will fix the problem you were complaining about, it is highly probable that other problems will occur as well. You might need to polyfill some other stuff as well, you might want to take a look into BabelJS in order to achieve this.



来源:https://stackoverflow.com/questions/57937221/docusaurus-fails-with-ie-object-doesnt-support-property-or-method-assign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!