簡體   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