diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index e79d7797767..dc36fc03641 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -259,7 +259,21 @@ module.exports = function (webpackEnv) { /* webpack-5-react-scripts end */ // this defaults to 'window', but by setting it to 'this' then // module chunks which are built will work in web workers as well. - globalObject: 'this', + /* webpack-5-react-scripts start */ + // Fix for issue: https://github.com/webpack/webpack/issues/6525#issuecomment-552140798 + // globalObject: 'this', + globalObject: `(() => { + if (typeof self !== 'undefined') { + return self; + } else if (typeof window !== 'undefined') { + return window; + } else if (typeof global !== 'undefined') { + return global; + } else { + return Function('return this')(); + } + })()`, + /* webpack-5-react-scripts end */ }, optimization: { minimize: isEnvProduction, diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 034a788e8fc..7f68d15afce 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "webpack-5-react-scripts", - "version": "4.0.2-next.2", + "version": "4.0.2-next.3", "description": "Configuration and scripts for Create React App using Webpack 5.", "repository": { "type": "git",