To fix Module not found: Can’t resolve ‘fs’ in Next.js application with JavaScript, we set the fs option to false.
For instance, we write
module.exports = {
webpack5: true,
webpack: (config) => {
config.resolve.fallback = { fs: false };
return config;
},
};
in webpack.config.js to set fs to false to disable the use of the fs module in the browser environment.