Skip to content

process.env should not be attached inside window object #2904

@vanbasten17

Description

@vanbasten17

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions