Webpack-dev-server: V2 - Module not found: Error: Can't resolve 'fs' in CLI

Created on 14 Apr 2017  路  7Comments  路  Source: webpack/webpack-dev-server

Hi, I am using webpack CLI for bundling Angualr2 files, and my config works for webpack CLI.

The I installed webpack-dev-server, but I couldn't get it running because of some exceptions.

Most of the exceptions are caused from running webpack plugins or loaders

I have read about #727 , but the solution doesn't work for CLI

Error message from console(the below is of them, but all of them were caused by Module not found: Error: Can't resolve 'fs' in..

ERROR in ./~/fs.realpath/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\...\node_modules\fs.realpath'
 @ ./~/fs.realpath/index.js 8:9-22
 @ ./~/shelljs/~/glob/glob.js
 @ ./~/shelljs/src/common.js
 @ ./~/shelljs/shell.js
 @ ./~/typedoc/dist/lib/converter/plugins/GitHubPlugin.js
 @ ./~/typedoc/dist/lib/converter/plugins/index.js
 @ ./~/typedoc/dist/lib/converter/index.js
 @ ./~/typedoc/dist/lib/application.js
 @ ./~/typedoc/dist/index.js
 @ ./~/typedoc-webpack-plugin/index.js
 @ ./webpack.common.config.js
 @ ./webpack.smartboard.config.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./webpack.config.js

webpack config

var WebpackNotifierPlugin = require('webpack-notifier');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpack = require("webpack");
var CommonChunks = require("webpack/lib/optimize/CommonsChunkPlugin.js");
var path = require("path");
var nodeExternals = require("webpack-node-externals");
var AotPlugin = require('@ngtools/webpack').AotPlugin;
var Visualizer = require("webpack-visualizer-plugin");
var TypedocWebpackPlugin = require('typedoc-webpack-plugin');

module.exports = {
    entry: {
        main: path.join(__dirname, 'app/main.ts'),
        vendor: path.join(__dirname, 'app/vendor.ts'),
        polyfill: path.join(__dirname, 'app/polyfill.ts'),
    },
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, '/asset')
    },
    resolve: {
        extensions: ['.ts', '.js']
    },
    plugins: [
        new AotPlugin({
            tsConfigPath: "./tsconfig-aot.json",
            entryModule: __dirname + "/app/app.module#SomeApp",
            mainPath: __dirname + "/app/main.ts",
        }),
        new CommonChunks({
            name: "common",
            filename: "commons.js",
            minChunks: 2
        }),
        new Visualizer(),
        new WebpackNotifierPlugin(),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.ENVIRONMENT)
        }),
    ],
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.ts?$/,
                loaders: ['@ngtools/webpack']
            },
            {
                test: /\.html$/,
                loader: 'html-loader',

            },
            {
                test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
                loader: 'file-loader?name=assets/[name].[hash].[ext]',

            },
            {
                test: /\.css$/,
                loader: 'raw-loader'
            },
            {
                test: /\.json/,
                loader: 'json-loader',
            },
            {
                enforce: 'pre',
                test: /\.js$/,
                loader: "source-map-loader"
            },
            {
                enforce: 'pre',
                test: /\.tsx?$/,
                loader: "source-map-loader"
            },
        ],
    },
};

webpack related package versions

...
+-- @ngtools/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]

node v7.9.0
OS: windows 10 Pro

Thanks for taking a look 馃槃

question

Most helpful comment

Personnally I had this problem using the command :
虁webpack-dev-sever webpack.config.dev.js --open

You must add the --config flag to put in a custom file.
虁webpack-dev-sever --config webpack.config.dev.js --open

Solved it for me.

All 7 comments

I'm getting the same issue, when using webpack-dev-server in conjunction with html-webpack-plugin

Adding
node: { fs: "empty" }

does not appear to help.

I am not very familiar with nodejs. Isn't fs a built-in module for nodejs?

Yes, but it's not available in the browser, which is what is triggering this error

+1

If someone can provide a simple test repo that we can reproduce this error with, we'd be more than happy to reopen and triage. Until then we're closing this one due to it's age.

Personnally I had this problem using the command :
虁webpack-dev-sever webpack.config.dev.js --open

You must add the --config flag to put in a custom file.
虁webpack-dev-sever --config webpack.config.dev.js --open

Solved it for me.

Thanks. I would take a try.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wojtekmaj picture wojtekmaj  路  3Comments

da2018 picture da2018  路  3Comments

movie4 picture movie4  路  3Comments

subblue picture subblue  路  3Comments

adiachenko picture adiachenko  路  3Comments