[Fix] Module not found Error Can’t resolve ‘fs’

I was trying to run the nextjs App, unfortunately I am facing the below error: Module not found: Error: Can’t resolve ‘fs’.

Below is the error snippet that I am seeing right now into my developer console log:

Module not found: Error: Can’t resolve ‘fs’

In this article, I am going to mention step-by-step process how I was was able to solve Module not found: Error: Can’t resolve ‘fs’ in Error.

Why Module not found: Error: Can’t resolve ‘fs’ in Error Occurred?

Module not found: Error: Can’t resolve ‘fs’ Error is basically seen because of angular-cli does not support modules in node like “fs” and “path”. That’s why it shows the below error:

Module not found: Error: Can’t resolve ‘fs’

How to Solve the Module not found: Error: Can’t resolve ‘fs’ Error?

To fix Module not found: Error: Can’t resolve ‘fs’ Error, For Webpack>5, you need to update the line “fs”: false into your webpack.config.js file. if currently you are not having the next.config.js file, then first, create it into root of your project and then again add the line “fs”: false. Now re-run the app, it would resolve the Module not found: Error: Can’t resolve ‘fs’ Error for you.

For Webpack>5, you need to update the line “fs”: false as shown below:

"fs": false

OR you just need to add fs: ’empty’:

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

Conclusion

To fix Module not found: Error: Can’t resolve ‘fs’ Error, For Webpack>5, you need to update the line “fs”: false into your webpack.config.js file. if currently you are not having the next.config.js file, then first, create it into root of your project and then again add the line “fs”: false. Now re-run the app, it would resolve the Module not found: Error: Can’t resolve ‘fs’ Error for you.

Module not found: Error: Can’t resolve ‘fs’ Error is basically seen because of angular-cli does not support modules in node like “fs” and “path”. That’s why it shows the Module not found Error Can’t resolve ‘fs’ Error.