I fixed the issue for user. He ran the command in wrong path so I ran the command in the right path and it worked.
For anyone else who stumbles here, he was using cPanel and to install extensions, you're supposed to run composer require in public_html directory, and not above it or inside the public folder.