Set target to node in webpack.config.js (default web )
module.exports = { target: 'node' };
In the above example, using node webpack will compile for use in a Node.js-like environment (uses Node.js, requires loading pieces, and do not touch any built-in modules, for example fs or path).
Alternatively, if this is not suitable for your use, you can also just change the libraryTarget to output (assuming you use CommonJS):
output: { path: path.resolve(__dirname, 'build'), filename: '[name].js', libraryTarget: 'commonjs' },
libraryTarget: "commonjs" - the return value of your entry point will be assigned to the export object using the value of output.library. In view, this means that it is used in CommonJS environments.
source share