chinese wemos d1 board randomly connecting/disconnecting from USB
The ESP8266 draws quite a lot of current, and does so in short pulses (e.g. when sending data on WiFi or writing to the Flash). The USB power supply is not able to cope with this, which leads the voltage to drop and the controller to reboot.
The solution is to provide a more stable power supply, by:

using a dedicated power supply that is able to deliver enough current and react quickly on changing power requirements.
adding some capacitors to the power supply. The D1 mini just has 20uF of capacity on the 3.3V rail. This is not sufficient if operating from a long USB cable. Try adding a 100uF capacitor in parallel and the board should work more stably.

Please note that operating the ESP8266 directly on an USB port is actually far outside the specification. A USB port is specified to deliver 100 mA at most (without special request from the device, which the D1 mini can not make), but the ESP8266 board will draw up to about 400mA in peak.