To fix Node cannot find module "fs" when using Webpack, we set target
to 'node'
.
For instance, in webpack.config.js, we write
module.exports = {
entry: "./app",
output: {
path: __dirname,
filename: "bundle.js",
},
module: {
loaders: [
{
test: /\.js$/,
exclude: "node_modules",
loader: "babel",
query: { presets: ["es2015"] },
},
],
},
target: "node",
};
to set target
to 'node'
to make Webpack build for Node.js instead of browser.