Skip to content

Commit

Permalink
fix(env): improve env detection compatibility for Node
Browse files Browse the repository at this point in the history
The React Native test environment *is* Node but sets up a window global: https://github.com/facebook/react-native/blob/7a85b911254dbae9fac4c6d8a862a20c33e0b36a/packages/react-native/Libraries/Core/setUpGlobals.js#L18

Reintroduce the navigator.userAgent check as a fallback for detecting a Node environment
  • Loading branch information
liamjones committed Jan 6, 2025
1 parent ae8cfaa commit f71100c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else if (typeof document === 'undefined' && typeof self !== 'undefined') {
// In worker
env.worker = true;
}
else if (!env.hasGlobalWindow || 'Deno' in window) {
else if (!env.hasGlobalWindow || 'Deno' in window || (navigator?.userAgent?.indexOf('Node.js') === 0)) {
// In node
env.node = true;
env.svgSupported = true;
Expand Down

0 comments on commit f71100c

Please sign in to comment.