Pouya Jabbarisani
Pouya Jabbarisani

Reputation: 1121

Uncaught Error: Cannot find module "fs" when using webpack

I'm using webpack + react + nodejs and this is my webpack config file:

when I open website on the browser, It returns Uncaught Error: Cannot find module "fs" on the browser.

var webpack = require('webpack');

var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: [
        'script-loader!./public/js/vendor/jquery.js',
        'script-loader!./public/js/vendor/foundation.min.js',
        'script-loader!./public/js/app.js',
        './view/app.jsx',
        './view/styles/main.scss'
    ],
    externals: {
        jquery: 'jQuery'
    },
    plugins: [
        new ExtractTextPlugin({
          filename: './public/styles/bundle.css',
          allChunks: true,
        }),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        })
    ],
    output: {
        path: __dirname,
        filename: './public/bundle.js'
    },
    resolve: {
        alias: {
            view: path.join(__dirname, 'view'),
            componentDir: path.join(__dirname, 'view/components/'),
            configureStore: path.resolve(__dirname, 'view/store/configureStore/'),
            actions: path.resolve(__dirname, 'view/actions/index/')
        },
        extensions: ['.js', '.jsx']
    },
    module: {
        rules: [
             ...
        ]
    }

};

Where is the problem?

Upvotes: 3

Views: 7165

Answers (1)

chautelly
chautelly

Reputation: 467

I think you have to add

node: {
  fs: 'empty',
},

to your webpack configuration. (https://webpack.js.org/configuration/node/#node)

Upvotes: 2

Related Questions