首页 > 解决方案 > Why does Edge not accept `undefined` in class instantiation but Chrome does? How do I fix?

问题描述

Who is right? Chrome or Edge and how do I fix it? Do I need to change the webpack configuration to make it compensate for this issue?

See screenshots below - undefined is being passed to new Headers() Chrome doesn't care but Edge throws error invalid argument and crashes entire app

enter image description here

enter image description here

标签: javascriptreactjsgoogle-chromewebpackmicrosoft-edge

解决方案


因为 IE(Edge 只是装扮 IE,让我们面对现实吧)是我们所有存在的祸根。

只要确保您传递的对象不是未定义的。您可以使用 javascripts truthy-ness 轻松做到这一点。

else {
    return new Headers(headers || {});
}

看起来这是来自 Apollo-Link-Rest。只需像这样创建您的 RestLink

const restLink = new RestLink({
  uri: 'https://swapi.co/api/',
  headers: {},
});

推荐阅读