I've picked up my Arduino MKR WiFi 1010 after a few months of not working with it and immediatly noticed weird behaviour. My device keeps constantly turning on and off for no apparent reason, be it connected to a pc or kept on battery life. When trying to upload my code to it, both through a port or through WiFi, it almost always produces an error of board not found since the devide keeps apparently disconnecting and connecting itself repeatedly.
Have you tried to delay the loading of the current sketch by the processor and uploading basic sketch like Blink? This can be done by pressing the Reset button twice quickly. This puts the chip in bootloader mode for 8 seconds during which you can attempt to upload the Blink sketch. If this works, try uploading your code. If your sketch stops turning on and off, you should be good to go. If it doesn't, repeat the reset process and look your sketch over, there is something in it that is causing the reboot.
Start by showing what you have connected to the Arduino.
Alternatively: don't connect anything to it except the USB cable to your computer. Does the problem persist?