Issue 1:
Bug report

What is the current behavior?

Bundling node library target with commonjs2 output type produces incorrect exports statements when dynamic import chunks are generated with prefetch hints.

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

Full repro case is available in this repo: https://github.com/dbanisimov/webpack-commonjs-exports-repro

Create a library with dynamic imports and prefetch hints:

// dep.js
export default () => console.log("dep");

// src.js
export default async () => {
import(/* webpackPrefetch: true */ './dep').then((res) => {
res.default();
console.log('lib');
})
}

Bundle for node commonjs2

module.exports = {
target: "node",
output: {
library: {
type: "commonjs2",
},
},
};

Import the bundled library and inspect the library exports

const lib = require('./dist/lib');
console.log(lib);

// => actual `undefined`
// => expected Object [Module] { default: [Getter] }

What is the expected behavior?

The expected behavior is preserving the entrypoint exports, including the default one.

Other

After digging around I've found that this extra webpack runtime code line is responsible for corrupting the exports

// webpack bundle mode: 'development'
// `__webpack_exports__` becomes `undefined` after the `__webpack_require__.O` function call
var __webpack_exports__ = __webpack_require__("./lib/lib.js");
__webpack_exports__ = __webpack_require__.O(__webpack_exports__);
module.exports = __webpack_exports__;

This line comes from the onChunksLoaded runtime call introduced in this change. I can confirm that downgrading to webpack@5.24 mitigates the issue.

Other relevant information:

webpack version: 5.25+

Node.js version: 14.16

Operating System: Ubuntu 20.04

Additional tools: -

Issue 2:
Bug report

What is the current behavior?

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

What is the expected behavior?

Other relevant information:

webpack version: 5.72.1

Node.js version: v16.14.2

Operating System: windows

Additional tools:

My configuration is going to look like this。

const BrowserReloadErrorOverlayWepbackPlugin = require('browser-reload-error-overlay-wepback-plugin');

let compiler = webpack({

// ... Omit the configuration

plugins: [

new BrowserReloadErrorOverlayWepbackPlugin(),

]

});

BrowserReloadErrorOverlayWepbackPlugin npm

https://www.npmjs.com/package/browser-reload-error-overlay-wepback-plugin

Main error code

I used it in the plugin compiler.watch

apply(compiler) {

compiler.watch({},(err, stats) => {

})

}

And then there was this mistake:

ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.

at Compiler.watch (K:\webpack-cli\node_modules\webpack\lib\Compiler.js:411:19)

at webpack (K:\webpack-cli\node_modules\webpack\lib\webpack.js:144:15)

at f (K:\webpack-cli\node_modules\webpack\lib\index.js:63:16)

at App.setCompiler (K:\webpack-cli@webpack-cli\compiler-server.js:96:26)

at App.middleware (K:\webpack-cli@webpack-cli\compiler-server.js:445:29)

at App.init (K:\webpack-cli@webpack-cli\compiler-server.js:67:14)

at processTicksAndRejections (node:internal/process/task_queues:96:5)