this is happening either when
- the solder holding the USB port has broken off the mainboard
- copper-plated pins are corroded / tired - usually this is the case
Of course, the normal solution would be to change/resolder, but
if the latter is the case, there is a trick which will help you for a time.
get an old male USB connector, which you would never use for nothing, spray generously WD40 or oil inside it. Let it drip away, then plug it few times into the laptop and wiggle it around for a bit. Don't leave or use the oily plug afterwards in the computer. THe oil from WD40 is conductive and might damage the laptop. This process should just break the corrosion and create a tiny film on the pins. It shouldn't leave visible oil droplets inside.
If this is not enough, there is another thing, but it requires practice. Turn off the laptop, unplug and take the battery out. Push a needle slightly inside the loop of each pin inside the USB. Repeat with more pressure until you see difference.
BUT, there is a huge risk, that a pin will jump out from the plastic if too much pressure is applied and it might not be as easy to put it back.
a design of first hw version of USB Type A (classic connector) is not taking in account different life expectancy for plug and socket.
Every connection usually has solid pins on one side against which, when connected, are pushing pins from the other side.
The connector with solid pins can last multiple times longer then the opposite.
Unfortunately, USB inside the computer - female, has these pushy pins, which won't last as long as those on the plug on the cable side. USB micro and USB v3 Type A have these reversed. So these connectors should last longer on the device's side.