I started the use the web pack version 4.42.0, I can build the web-pack and able to run it. But whenever I include below code. I get an error, Please would anyone can help how to use npm fs in web-pack
Index.js
var fs = require('fs');
console.log(fs.readFileSync());
and my webpack-config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
options: { minimize: true }
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
{
test: /\.node$/,
use: 'node-loader'
}
],
},
plugins: [new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "./index.html"
},
)],
mode: 'development',
node: { fs: 'empty' },
target: "node"
};
I am facing the error
Uncaught TypeError: fs.readFileSync is not a function
After removing node and target from webpack-config.js
ERROR in ./src/index.js Module not found: Error: Can't resolve 'fs' in '/Users/nagaraj/gowork/src/github.com/webpack_tutor/src' @ ./src/index.js 1:9-22
package.json
"devDependencies": {
"@babel/core": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"babel-loader": "^8.0.6",
"file-loader": "^5.1.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"node-loader": "^0.6.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"fs": "0.0.1-security",
"lodash-webpack-plugin": "^0.11.5",
"webpack-dev-server": "^3.10.3"
}