close

[Solved] Module not found: Error: Can’t resolve ‘fs’ in

Hello Guys, How are you all? Hope You all Are Fine. Today I Just upgraded Angular from 6 to 8. But I am facing the following error Module not found: Error: Can’t resolve ‘fs’ in angular. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Module not found: Error: Can’t resolve ‘fs’ in Error Occurs ?

Today I Just upgraded Angular from 6 to 8. But I am facing the following error.

ERROR in ./node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'fs' in 'E:\Project\Milan\nien\vital10-frontend\node_modules\resolve\lib'
ERROR in ./node_modules/resolve/lib/sync.js
Module not found: Error: Can't resolve 'fs' in 'E:\Project\Milan\nien\vital10-frontend\node_modules\resolve\lib'
ERROR in ./node_modules/resolve/lib/node-modules-paths.js
Module not found: Error: Can't resolve 'fs' in 'E:\Project\Milan\nien\vital10-frontend\node_modules\resolve\lib'
ERROR in ./node_modules/tslint/lib/utils.js

How To Solve Module not found: Error: Can’t resolve ‘fs’ in Error ?

  1. How To Solve Module not found: Error: Can’t resolve ‘fs’ in Error?

    To Solve Module not found: Error: Can’t resolve ‘fs’ in Error This error is because of angular-cli does not support modules in node like “fs” and “path”. Add the following to the “package.json” file.

  2. Module not found: Error: Can’t resolve ‘fs’ in

    To Solve Module not found: Error: Can’t resolve ‘fs’ in Error This error is because of angular-cli does not support modules in node like “fs” and “path”. Add the following to the “package.json” file.

Solution 1: Set “fs”: false,

This error is because of angular-cli does not support modules in node like “fs” and “path”. Add the following to the “package.json” file.

"browser": {
  "fs": false,
  "path": false,
  "os": false
}

Solution 2: set fs: ’empty’

the solution is to add this to the webpack config:

config.node = {
  fs: 'empty',
}

Solution 3: if you use NuxtJS

If you are using NuxtJs then

// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
    extend(config, {}) {
        config.node = {
            fs: 'empty'
        }
    }
},

Solution 4: For Webpack > 5

For Webpack > 5 update webpack.config.js

module.exports = {
    ...
    resolve: {
        fallback: {
            "fs": false
        },
    }
}

Solution 5: Just add {node:'empty'}

Just add {node:'empty'} to your webpack.config file.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

Leave a Comment