webpack-dev-server: process.env should not be attached inside window object

Bug report

What is the current behavior? Just setted a set of compilation rules to compile a web project along with webpack-dev-server, here’s an example:

function botonicDevConfig(mode) {
  return {
    mode: mode,
    devtool: sourceMap(mode),
    target: 'web',
    entry: path.resolve('webpack-entries', 'dev-entry.js'),
    module: {
      rules: [
        babelLoaderConfig,
        babelLoaderConfig2,
        fileLoaderConfig,
        stylesLoaderConfig,
      ],
    },
    output: {
      filename: 'webchat.botonic.js',
      library: 'Botonic',
      libraryTarget: 'umd',
      libraryExport: 'app',
    },
    resolve: resolveConfig,
    devServer: {
      static: [
        path.join(__dirname, 'dist'),
        path.join(__dirname, 'src', 'nlu', 'models'),
      ],
      liveReload: true,
      historyApiFallback: true,
      hot: true,
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: path.resolve(botonicPath, 'src', 'webchat.template.html'),
        filename: 'index.html',
      }),
      new webpack.HotModuleReplacementPlugin(),
      imageminPlugin,
    ],
  }
}

After running the command webpack serve --env target=dev --mode=development and opening the browser, process object comes inside the definition of window object (attached screenshot), with env set as an empty object. See that I’m not using any kind of Environment or Define Plugin, I don’t want to have process defined. In previous versions (webpack 4), this variable was undefined (as far as I understand, this should be the common behavior). Screenshot 2020-12-02 at 22 25 50

If the current behavior is a bug, please provide the steps to reproduce. After setting above rules,

What is the expected behavior? process.env should not be attached by default. It should be enabled (in any case) after using some of the plugins to define env variables.

Other relevant information: webpack version: 5.9.0 Node.js version: v10.23.0, also tried v12.20.0 with same results. Operating System: macOS Catalina 10.15.7 Additional tools:

"webpack": "^5.9.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^4.0.0-beta.0" (I needed to update dev server in order to make it work, it seems to be broken with latest v3.11.0).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Yep, with this week, I am fully focus on webpack-dev-server, IE 11 will be fixed in the next release

WIP on IE 11 compatibility

Hope this week

Fixed https://github.com/webpack/webpack-dev-server/pull/2971, sorry for delay, really many issues

Same issue here with latest versions of all webpack - related packages with IE 11, than the one reported on https://github.com/webpack/webpack-dev-server/issues/2918

‘Symbol’ is undefined

https://github.com/webpack/webpack-dev-server/blob/master/client-src/transpiled-modules/log.js

Is there any progress on this issue @alexander-akait Symbol still report errors on low version terminals #2900

Sorry, no, but I think this month, it is already stable in 99% cases so you can use it