File tree 2 files changed +12
-4
lines changed
packages/react-app-polyfill
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,12 @@ if (typeof Promise === 'undefined') {
14
14
window . Promise = require ( 'promise/lib/es6-extensions.js' ) ;
15
15
}
16
16
17
- // fetch() polyfill for making API calls.
18
- require ( 'whatwg-fetch' ) ;
17
+ // Make sure we're in a Browser-like environment before importing polyfills
18
+ // This prevents `fetch()` from being imported in a Node test environment
19
+ if ( typeof window !== 'undefined' ) {
20
+ // fetch() polyfill for making API calls.
21
+ require ( 'whatwg-fetch' ) ;
22
+ }
19
23
20
24
// Object.assign() is commonly used with React.
21
25
// It will use the native implementation if it's present and isn't buggy.
Original file line number Diff line number Diff line change @@ -14,8 +14,12 @@ if (typeof Promise === 'undefined') {
14
14
window . Promise = require ( 'promise/lib/es6-extensions.js' ) ;
15
15
}
16
16
17
- // fetch() polyfill for making API calls.
18
- require ( 'whatwg-fetch' ) ;
17
+ // Make sure we're in a Browser-like environment before importing polyfills
18
+ // This prevents `fetch()` from being imported in a Node test environment
19
+ if ( typeof window !== 'undefined' ) {
20
+ // fetch() polyfill for making API calls.
21
+ require ( 'whatwg-fetch' ) ;
22
+ }
19
23
20
24
// Object.assign() is commonly used with React.
21
25
// It will use the native implementation if it's present and isn't buggy.
You can’t perform that action at this time.
0 commit comments