I had the same problem on my RasPi 3B+. The compile_process_limit: 1 option didn’t help. The compile would fail at random points, which is consistent with a memory shortage. What did work is running it on a different computer, as others have said above and in the thread at Esphome killing home assistant (a very good resource for this issue). As an extra bonus, compiling on my Windows machine is MUCH faster. The downside is that you have to learn to use the ESPHome command line interface, but the only command you really need to use is “esphome run <file.yaml>”. The commands are listed at Command Line Interface — ESPHome.
First, install ESPHome on your computer by following the steps at Installing ESPHome Manually — ESPHome. You have to install Python, then use pip to install esphome. The steps in the guide are pretty clear and they worked for me with no problem.
Then make a working folder and copy the yaml file from your HA ESPhome dashboard into that folder. Open a Windows command window (Start > type “cmd”) and cd into the working folder). Then type the command “esphome run yaml-file-name”). ESPHome will compile the yaml and load it OTA or by USB onto your ESP device. You will probably recognize what it is doing since it looks like the ESPHome dashboard results.
When it works, it is pretty painless, and pretty fast. And best of all, since the compile is done on your Windows (or Mac) machine, it doesn’t use any memory on the RasPi or HA device. You don’t need to stop other processes or addons. You can edit the yaml file on your Windows machine using Notepad, or you can edit it on the ESPHome dashboard if you want the indentation markings and red squiggly lines showing errors.
Once the yaml is compiled and loaded onto the ESP device, the ESP will communicate with the HA device like normal. In other words, compiling and loading from the “big” computer doesn’t affect how the ESP devices communicates with the Home Assistant computer.
This post doesn’t say anything that other people haven’t said better already (thanks). I’m mainly trying to say that (1) don’t be afraid to run ESPHome on a different computer, (2) don’t be afraid of the CLI, you probably only need one command, and (3) this solves the compilation problems completely by moving the compilation to a stronger computer.