From fe29429268fc2e0c36bfefb64a5ad73451a2fe54 Mon Sep 17 00:00:00 2001 From: Gregory Shilin Date: Tue, 13 Nov 2018 16:40:59 +0200 Subject: [PATCH] Don't polyfill fetch for Node -- additional files --- packages/react-app-polyfill/ie11.js | 8 ++++++-- packages/react-app-polyfill/ie9.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/react-app-polyfill/ie11.js b/packages/react-app-polyfill/ie11.js index 15a7a9a085b..e7e3d6b71a0 100644 --- a/packages/react-app-polyfill/ie11.js +++ b/packages/react-app-polyfill/ie11.js @@ -14,8 +14,12 @@ if (typeof Promise === 'undefined') { window.Promise = require('promise/lib/es6-extensions.js'); } -// fetch() polyfill for making API calls. -require('whatwg-fetch'); +// Make sure we're in a Browser-like environment before importing polyfills +// This prevents `fetch()` from being imported in a Node test environment +if (typeof window !== 'undefined') { + // fetch() polyfill for making API calls. + require('whatwg-fetch'); +} // Object.assign() is commonly used with React. // It will use the native implementation if it's present and isn't buggy. diff --git a/packages/react-app-polyfill/ie9.js b/packages/react-app-polyfill/ie9.js index ef89d14fa40..9f355f28f21 100644 --- a/packages/react-app-polyfill/ie9.js +++ b/packages/react-app-polyfill/ie9.js @@ -14,8 +14,12 @@ if (typeof Promise === 'undefined') { window.Promise = require('promise/lib/es6-extensions.js'); } -// fetch() polyfill for making API calls. -require('whatwg-fetch'); +// Make sure we're in a Browser-like environment before importing polyfills +// This prevents `fetch()` from being imported in a Node test environment +if (typeof window !== 'undefined') { + // fetch() polyfill for making API calls. + require('whatwg-fetch'); +} // Object.assign() is commonly used with React. // It will use the native implementation if it's present and isn't buggy.