The sketch compiled. The fault is the connection or the chip not being in flash mode.
Causes
The 4 usual causes in order
1The wrong port or the wrong board is selected
espcomm talks to the port you chose, at the speed of the board you chose.
Pick the port that appears when you plug the board in.
Pick the board you have, such as NodeMCU 1.0 (ESP-12E Module) or Generic ESP8266 Module.
2GPIO0 is not low during the upload
Bare ESP-01 and ESP-12 modules need GPIO0 pulled low to enter flash mode. A NodeMCU does this by itself.
On a bare module, connect GPIO0 to GND, reset, upload, then remove the wire.
On a NodeMCU, hold FLASH while the upload connects, then let go.
3The upload speed is too high
Cheap cables and long wires lose bytes at high speeds.
In Tools, set Upload Speed to 115200 or lower.
4Not enough power, or no driver
The module draws bursts of current when it connects to WiFi, and a sagging supply resets it.
Power a bare module from a stable 3.3 V supply, not from the 3.3 V pin of an Uno.
Install the driver for the USB chip, a CH340 or CP210x, on Windows.
On a real board
What to do at the bench
Mokxi's Upload to board writes to an ESP8266, such as a NodeMCU or a D1 mini, from Chrome or Edge, through the same ROM bootloader esptool talks to, so the same fixes apply.
Run the sketch in Mokxi before you blame the board. If it builds and runs there, the code is fine and the problem is the connection to the real board.
Test the sketch in Mokxi first
Run the sketch here before you blame the board. If it builds and runs in Mokxi, the code is fine and the fault is the connection to the real board. Mokxi never uploads in a simulation, so it cannot raise this error itself.