This error might come after upgrading the Mac OS.
I encounter this error when I was trying to upgrade some brew packages in my machine and saw the below error message:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
To resolve this you need ti to install Xcode command line tool
xcode-select --install
or
xcode-select --reset
And now the problem resolved 😁