diff --git a/packages/scheduler/npm/index.js b/packages/scheduler/npm/index.js index 68a443aa1de8b..3a7a8b897e6ba 100644 --- a/packages/scheduler/npm/index.js +++ b/packages/scheduler/npm/index.js @@ -1,9 +1,24 @@ 'use strict'; -if (typeof window === 'undefined' || typeof MessageChannel !== 'function') { - module.exports = require('./unstable_no_dom'); -} else if (process.env.NODE_ENV === 'production') { - module.exports = require('./cjs/scheduler.production.min.js'); +// Duplicated from 'react/packages/shared/ExecutionEnvironment.js' +var canUseDom = !!( + typeof window !== 'undefined' && + typeof window.document !== 'undefined' && + typeof window.document.createElement !== 'undefined' +); + +// Checks if this is global space to catch +// execution in node environments and use 'unstable_no_dom' +// +// eslint-disable-next-line no-undef +var isThisGlobal = !!(typeof globalThis !== 'undefined' && globalThis === this); + +if (canUseDom && isThisGlobal) { + if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/scheduler.production.min.js'); + } else { + module.exports = require('./cjs/scheduler.development.js'); + } } else { - module.exports = require('./cjs/scheduler.development.js'); + module.exports = require('./unstable_no_dom'); }