IDE only compiles one time

Using W10, Arduino 1.8.13, with a Mega2560.

My code compiles fine the first time, then further attempts get the message
"Error compiling for board Arduino Mega or Mega 2560." I have to close the IDE and restart to compile or upload again.

I saw a few threads from 2018 that indicated OneDrive was the problem and would be fixed in the next version. But 2 years later I'm seeing it.

I moved the project out of OneDrive, but I still get this error. I also saw a thread about turning off
"Aggressively Cache Compiled Core", which I couldn't find. I did find "compiler.cache_core" and turned it off, but no change.

Any ideas?

I’m still on IDE 1.8.5; “Aggressively Cache Compiled Core” is in file->preferences.

I’m not sure what else to try. There are more knowledgeable people here.

One thing that I would try is to rename preferences.txt (after closing the IDE). On windows you can find it in C:\Users\yourUsername\AppData\Local\Arduino15.

Another thing that I would try is to delete that complete directory (make a backup).