Ref. Answer
In addition to her solution, I added EnvironmentPlugin in webpack.config.js:
...plugins: [new webpack.ProvidePlugin({process: 'process/browser'}),new webpack.EnvironmentPlugin({PATH_MODERN: 'dist/modern/domready.min.js',PATH_LEGACY: 'dist/legacy/domready.min.js',DEBUG: false}),...]
and using it in index.js
if (process.env.PATH_LEGACY) {// ...}
For anyone still struggling with this here's something you could try:
Replace the process/browser
with process
or process/browser.js
new webpack.ProvidePlugin({process: 'process'})
With webpack 5 and ES6 modules I think there's some difficulty in package resolution here, which is why we need a better path for the process.
Otherwise try including this in your webpack.config:
resolve: {fallback: {'process/browser': false,}},
This can work to overcome the error, but not sure if it doesn't actually break the place where it's being used. In my case the first suggestion worked out.
Easy way: prepend the variable "NODE_ENV" when you call webpack i.e. NODE_ENV=production webpack --watch