For future readers (mostly myself) who run into this issue, there's another important factor that could be causing this error or similar errors which is extremely hard to realize: conflicting versions of Rust and/or Cargo. This means it persists even after running rustup target add wasm32-unknown-unknown.
In my case, I had rust installed from brew and rustup at the same time, which was causing a bunch of confusion and clashes. You should make sure you have Rust installed exclusively from rustup. Double check every package manager you have on your system, because rust may have been installed as a dependency of another package, such as through cargo-nextest in my case. Such packages should be uninstalled and managed instead through cargo itself, and thus kept under the purview of rustup.