1

使用 babel-preset-env、babel-polyfill 库构建。

错误:未处理的承诺拒绝类型错误:方法 Promise.prototype.then 调用了不兼容的接收器函数(t){this._c=[],this._a=void 0,this._s=0,this._d=!1,this ._v=void 0,this._h=0,this._n=!1}

getEvents: async function() {
    const response = await fetch(
        '/api/v1/event/'
      {
        credentials: 'same-origin'
      }
    );

    // get Success
    this.events = await response.json();
    ...
}

包.json

"babel-polyfill": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"babel-preset-env": "^1.6.0",
"grunt-babel": "^6.0.0",

如果有人知道是什么原因造成的,请回答。

我认为可能是一个 promise polyfill 问题.. 因为 function(t){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1}这个函数来自 promise polyfill..

babel-polyfil 模块中的堆栈跟踪。

var $resolve = function (value) {
  var promise = this;
  var then;
  if (promise._d) return;
  promise._d = true;
  promise = promise._w || promise; // unwrap
  try {
    if (promise === value) throw TypeError("Promise can't be resolved itself");
    if (then = isThenable(value)) {
      microtask(function () {
        var wrapper = { _w: promise, _d: false }; // wrap
        try {

错误发生在下一行

          then.call(value, ctx($resolve, wrapper, 1), ctx($reject, wrapper, 1)); 
        } catch (e) {
          $reject.call(wrapper, e);
        }
      });
    } else {
      promise._v = value;
      promise._s = 1;
      notify(promise, false);
    }
  } catch (e) {
    $reject.call({ _w: promise, _d: false }, e); // wrap
  }
};

抱歉,我无法重新生成错误。我记得它是在该行中触发的。

4

0 回答 0