Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Abrahamghaemi's avatar

Module not found: Error: Can't resolve 'fs'

hi, when run gulp get error not found fs module

// depend fs
let dir = require('node-dir');
//or 
let fs = require('fs');

dir.path(__dirname, function(err, paths){
    console.log(paths.dirs);
    console.log(paths.files);
    console.log(paths);
});

result

gulp
 
[01:02:59] Using gulpfile ~/ibrahem_ghaemi/laravel/gulpfile.js
[01:02:59] Starting 'all'...
[01:02:59] Starting 'webpack'...
{ [Error: ./resources/assets/js/router.js
Module not found: Error: Can't resolve 'fs' in '/Users/user/ibrahem_ghaemi/laravel/resources/assets/js'
resolve 'fs' in '/Users/user/ibrahem_ghaemi/laravel/resources/assets/js'
  Parsed request is a module
  using description file: /Users/user/ibrahem_ghaemi/laravel/package.json (relative path: ./resources/assets/js)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Users/user/ibrahem_ghaemi/laravel/package.json (relative path: ./resources/assets/js)
    resolve as module

0 likes
8 replies
Dan's avatar

Have you installed "fs" via NPM?

What does your package.json file look like?

Abrahamghaemi's avatar

 npm install fs
/Users/user/ibrahem_ghaemi/laravel
└── [email protected]

package.json

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "bootstrap-sass": "^3.3.7",
    "gulp": "^3.9.1",
    "jquery": "^3.1.0",
    "json-loader": "^0.5.4",
    "laravel-elixir": "^6.0.0-9",
    "laravel-elixir-browserify-official": "^0.1.3",
    "laravel-elixir-rollup-official": "^1.0.4",
    "laravel-elixir-vue": "^0.1.4",
    "laravel-elixir-webpack-official": "^1.0.2",
    "lodash": "^4.14.0",
    "vue": "^2",
    "vue-resource": "^0.9.3"
  },
  "dependencies": {
    "fs": "0.0.1-security",
    "intl-relativeformat": "^1.3.0",
    "merge": "^1.2.0",
    "vue-locale": "^0.4.0"
  }
}
secondman's avatar

@xsigns @ibrahem

You can resolve this in your Laravel Mix file like so:

mix.webpackConfig({
    node: {
      fs: "empty"
    },
    resolve: {
        alias: {
            "handlebars" : "handlebars/dist/handlebars.js"
        }
    },
});
11 likes
nouvre's avatar

I know it's an old thread, but I got this error because i added a profile section to a Spark application. And I added the pointer in the wrong bootstrap.js file. I had to add it to the one inside resources/assets/js/spark-components, rather than the other in resources/assets/js/components. That fixed it for me.

Please or to participate in this conversation.