If you recently updated your macOS and started to get this error when running yarn or npm, this is the guid to help you solve this problem.
The solution is simple but not easy to execute, we need to reinstall the command line tools, Xcode.
First off, check that you have Xcode installed on your computer. In your terminal run
If you dont have Xcode installed this will start the process and once installed, your problem is solved.
If you have Xcode installed and need to fix the problem with No Xcode or CLT version Detected! We need to reinstall it.
Get the path of your current version of Xcode
The output should be something like this /Library/Developer/CommandLineTools
When you have the path for your current version of Xcode you need to delete that folder in order to start a fresh installation.
sudo rm -r -f /Library/Developer/CommandLineTools
Now that you succeed with removing the CommandLineTools folder, you need to start install Xcode.
Click the install button on the dialog that appears, wait a few minites and then you are all done!