Skip to content

Commit eda5e68

Browse files
Fix error in alternative JS environments (#2500)
1 parent 84522de commit eda5e68

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/hip-cherries-arrive.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/react': patch
3+
---
4+
5+
Fix error loading @emotion/react in alternative JS environments

packages/react/src/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ if (process.env.NODE_ENV !== 'production') {
2020
const isJest = typeof jest !== 'undefined'
2121

2222
if (isBrowser && !isJest) {
23-
const globalContext = isBrowser ? window : global
23+
// globalThis has wide browser support - https://caniuse.com/?search=globalThis, Node.js 12 and later
24+
const globalContext =
25+
// $FlowIgnore
26+
typeof globalThis !== 'undefined'
27+
? globalThis // eslint-disable-line no-undef
28+
: isBrowser
29+
? window
30+
: global
2431
const globalKey = `__EMOTION_REACT_${pkg.version.split('.')[0]}__`
2532
if (globalContext[globalKey]) {
2633
console.warn(

0 commit comments

Comments
 (0)