Modules wrapped in arrow options even for preset-env with arrow functions transpiling enabled

Bug Report

Context
I use the Babel (babel/core 7.11.0 and babel/preset-env 7.11.0) via babel-loader (8.1.0) via grunt-babel (8.0.0).

Current behavior
In generated bundles, the modules are wrapped in arrow functions in constructs like:

((module, __unused_webpack_exports, __webpack_require__) => {
eval("code goes here");
});

The content of modules transpiled properly (no arrow functions inside modules).

Expected behavior
It is expected with preset-env with targets having “ie”:”11″, that output would look like

(function(module, __unused_webpack_exports, __webpack_require__) {
eval("code goes here");
});

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
The Babel configuration via babel-loader , the rule for js/jsx files:

        {
            test: /\.(js|jsx)$/,
            exclude: /(node_modules)/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                        ['@babel/preset-react'],
                        ['@babel/preset-env',       {
                            "corejs": {
                                "version": 3
                            },
                            "useBuiltIns": "entry",
                            "targets": {
                                browsers: "> 1%%"
                                /*
                                "ie": "11",
                                "chrome": "55",
                                "firefox": "52",
                                "edge": "15",
                                "safari": "11",
                                "opera": "42"
                                 */
                            }
                        }]
                    ],
                    "plugins": [
                        "@babel/plugin-transform-arrow-functions",
                        "@babel/plugin-transform-async-to-generator",
                        "@babel/plugin-transform-runtime"
                    ]
                }
            },
        },

Environment
npx: installed 1 in 3.3s

System:
OS: Windows 10 10.0.19041
Binaries:
Node: 12.18.0 – C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 – ~\AppData\Roaming\npm\yarn.CMD
npm: 6.14.5 – C:\Program Files\nodejs\npm.CMD
npmPackages:
@babel/core: ^7.11.0 => 7.11.0
@babel/plugin-transform-arrow-functions: ^7.10.4 => 7.10.4
@babel/plugin-transform-async-to-generator: ^7.10.4 => 7.10.4
@babel/plugin-transform-runtime: ^7.11.0 => 7.11.0
@babel/preset-env: ^7.11.0 => 7.11.0
@babel/preset-react: ^7.10.4 => 7.10.4
@babel/runtime: ^7.11.0 => 7.11.0
babel-loader: ^8.1.0 => 8.1.0
grunt-babel: ^8.0.0 => 8.0.0
webpack: ^5.0.0-beta.14 => 5.0.0-beta.14

Possible Solution
Add some switch like legacyModulesWrap:boolean , with default value false enforcing non-arrow functions for modules wrapping if set to true

1 possible answer(s) on “Modules wrapped in arrow options even for preset-env with arrow functions transpiling enabled