From 25d314414f5f4b54ef713c03063644d17a3a01a6 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 2 Aug 2019 14:17:27 +0200 Subject: [PATCH] fix: use node-fetch in electron-renderer `fetch` needs to be polyfilled before importing ky-universal: ky-universal won't use node-fetch because electron-renderer already has global.fetch defined and we can't use the one from electron-renderer as it returns different errors and makes HTTPS mocking impossible in tests License: MIT Signed-off-by: Marcin Rataj --- src/core/components/files-regular/add-from-url.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/components/files-regular/add-from-url.js b/src/core/components/files-regular/add-from-url.js index eb9e5836a6..8142db5d9b 100644 --- a/src/core/components/files-regular/add-from-url.js +++ b/src/core/components/files-regular/add-from-url.js @@ -1,8 +1,17 @@ 'use strict' const { URL } = require('iso-url') -const { default: ky } = require('ky-universal') const nodeify = require('promise-nodeify') +const { isElectronRenderer } = require('ipfs-utils/src/env') +if (isElectronRenderer) { + // `fetch` needs to be polyfilled before importing ky-universal: + // ky-universal won't use node-fetch because electron-renderer already has global.fetch defined + // and we can't use the one from electron-renderer as it returns different + // errors and makes HTTPS mocking impossible in tests + // TODO: remove when upstream fix lands + global.fetch = require('node-fetch') +} +const { default: ky } = require('ky-universal') module.exports = (ipfs) => { const addFromURL = async (url, opts = {}) => {