This also happens if you are using nx with an incompatible nodejs version mostly becuase you are using nvm to manage multiple versions of node (say 14 and 20).
To solve this, make sure to switch to the recent version of node (20) with
nvm use 20
Now install nx with your latest node
npm install -g nx