繁体   English   中英

Angular 11 - 类型错误:无法在“窗口”上执行“获取”:非法调用

[英]Angular 11 - TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation

我正在使用本身依赖于isomorphic-unfetch的依赖项。 在 Angular 11 项目中,我可以执行 isomorphic-unfetch 本身而不会出现任何错误。 当使用内部使用 isomorphic-unfetch 来获取的依赖项(通过 npm 安装)时,我收到以下消息:

index.js:209 TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
at zone-evergreen.js:1465
at Object.proto.<computed> [as default] (zone-evergreen.js:975)
at index.js:189
at step (index.js:70)
at Object.next (index.js:51)
at index.js:44
at new ZoneAwarePromise (zone-evergreen.js:1387)
at __awaiter (index.js:40)
at index.js:380

当集成到 React 或纯 JS/TS 中时,依赖项工作正常。 我在这里发现了一些相关的问题,这些问题并未具体针对 Angular。

由于 Angular 提供了他们自己的库来制作 http 请求HttpClientModuleHttpClient通常不需要像unfetch等第三方库。这就是没有人在 DEdocs 或其他地方定位 ZC31C335EF37283C451B18BA0DD317 的原因。

但是应该仍然可以使用该库。 在您的情况下,我能想到的一些提示出错了:

  • Window用大写字母W而不是w书写。
  • 也许您需要初始化一些对等依赖项,例如import 'unfetch'以运行它们的默认脚本(然后将 fetch function 添加到 window 对象)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM