pug-loader: Cannot resolve module 'fs'

Hey there, thanks for the loader,

I get the following warning when running Webpack with this loader.

WARNING in ./~/jade/lib/runtime.js
Module not found: Error: Cannot resolve module 'fs' in /Users/Username/Dev/www/project/node_modules/jade/lib
 @ ./~/jade/lib/runtime.js 180:18-31

I think found a possible solution which I think you actually gave @sokra. https://gitter.im/webpack/webpack/archives/2014/08/26 looks like you need to add

"browser": { "fs": false } https://github.com/kangax/fabric.js/blob/master/package.json#L17-L21

Could be alos that I screwed something up, thanks in advance for any help

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 7
  • Comments: 20

Commits related to this issue

Most upvoted comments

add this to your config:

node: {
  fs: "empty"
}

add this to your config:

node: { fs: “empty” }

This can also be fixed on library level. The library using fs can add this to the package.json:

"browser": {
  "fs": false
}

to say: “For browser build I don’t need the fs package. Give me an empty one.”.

I have already added that code but unfortunately I am still having the same error. Below is my code

module.exports = { entry: __dirname + “/app/assets/scripts/app.js”,

output: {
    path: __dirname + "/app/temp/scripts",
    filename: "app.js"
},
module: {
    loaders: [
        {
            test: /\.js$/,
            exclude: 'node_modules',
            loader: 'babel-loader',
            query: {
                presets: ['es2015']
            },
            
            

        }
    ]
},
 node: {
    fs: 'empty',
    // tls: 'empty'
}

}

@afoysal in case anyone is still confused. it should be added like:

var config = {
    node: {
        fs: "empty"
    }
}

I don’t understand why I’m getting this error, because I’m only using the path module in my webpack.config.js. Shouldn’t it only complain if my browser code accidentally requires path?

I solved with: target: "async-node"

target: “async-node”

@omerts (just my guess) setting fs to empty tells webpack that there is NO implementation of the fs module. Take a look at this node-lib-browser module. By default, webpack’s target is ‘web’. There is no implementation for some of the node core libraries, such as fs, os, net, etc. That is where ‘node-lib-browser’ comes into the picture. For fs, there is NO implementation, and thus should be set as empty. You may want to first check why you have fs as a dependency.