gyp: No Xcode or CLT version detected! 👈 I think I know why this happens

👉 Did you solve it by sudo rm -r -f /Library/Developer/CommandLineTools and then re-installing it with xcode-select --install, only to inexplicably run into the exact same error a while later?

Here's the kicker...

👉👉 Are you a user of a Node version manager like asdf or nvm? 👈👈

I've been in this position a number of times in the last few months and I could never understand why it kept cropping up. But I think I've discovered why I continually, and intermittently had this issue.

I was working on a few older projects using Node 8. I wrapped one up yesterday and moved to a new React project this morning and so I nvm use 12.15 and ran npm i

gyp: No Xcode or CLT version detected!

😔

So I begrudgingly deleted Xcode CLT and re-installed and everything worked fine. And then it clicked.

I think xcode-select --install attaches itself to the node version you have installed at the time

So you fix the problem, and then, later on, run into it again when you switch to a different version of Node.

Haven't tested this thoroughly... who has the time. But would love to hear if this resonates with anyone else and maybe this is actually the case?

Do you use nvm or asdf as described above? IE can you replicate my hypothesis here, that you install the CLI tools in one version of node, and then you run into GYP issues when you switch to another version?