'Error: Can't resolve 'fs' in node_modules\dotenv\lib' in React web app

I installed dotenv using npm install --save dotenv in my React web application. Whenever I use require('dotenv') this error comes up.

Error: Can't resolve 'fs' in node_modules\dotenv\lib'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source