I tried reinstalling Mojave in disk recovery mode but the problem persisted. I tried resetting the PRAM and SMC. No change.
I called apple support and we tried to go back to High Sierra (or Sierra which came on the iMac) but the computer could not identify the hard drive and disk repair would not work on the drive.
I went to the apple store. Their initial diagnostics could not find the problem. When trying to install High Sierra, it indicated the hard drive was locked. They tried unmounting and mounting the drive to no avail. They next tried wiping the drive but it did not respond.
So they took the computer overnight to do repairs. They said that there was a problem in the disk formatting. They wiped the disk and installed High Sierra. Fortunately I had a Time Machine backup.
I suspect that we may al have this disk "formatting" problem. Idk how it came to be. They said that I should have no problem going to Mojave now that the disk was wiped and reformatted. But I'm going to wait.
Maybe Apple will release info on this "formatting issue" so that people can fix it before they upgrade.