Webpack replaces `this` with `undefined` in IIFEs

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?

(function() {
    console.log(this);
}).call("Hello");

Inside an ES modules results to:

(function () {
    console.log(undefined);
}).call("Hello");

If the current behavior is a bug, please provide the steps to reproduce.

Create an entry point with such code:

export function hello() {
    console.log("Hello 1");
}

(function() {
    console.log(this);
}).call("Hello 2");

Run Webpack and see the output. But if you remove the exported function, then this returns back.

What is the expected behavior?

Should not remove this.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Webpack 4.5.0
Dev mode. Target is umd library.

Author: Fantashit

1 thought on “Webpack replaces `this` with `undefined` in IIFEs

Comments are closed.