Trouble uploading a simple sketch

I have been using PlatformIO for a year or two and I had to rebuild my laptop. After installing Visual Studio Code and the PlatformIO extension I created a simple sketch please see below
#include <Arduino.h>

void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.println(" Hello ");
delay(1000);
}

I compiled it first and then uploaded it and it gave me the following error

*** [upload] UnboundLocalError : local variable ‘port’ referenced before assignment
Traceback (most recent call last):
File “C:\Users\andre.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Action.py”, line 1318, in execute
result = self.execfunction(target=target, source=rsources, env=env)
File “C:\Users\andre.platformio\platforms\espressif32\builder\main.py”, line 35, in BeforeUpload
env.AutodetectUploadPort()
File “C:\Users\andre.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737, in call
return self.method(*nargs, **kwargs)
File “C:\Users\andre.platformio\penv\lib\site-packages\platformio\builder\tools\pioupload.py”, line 113, in AutodetectUploadPort
UPLOAD_PORT=SerialPortFinder(
File “C:\Users\andre.platformio\penv\lib\site-packages\platformio\device\finder.py”, line 156, in find
return best_port or port
UnboundLocalError: local variable ‘port’ referenced before assignment

I have tried uninstalling and PlatformIO and VSCode but no joy, I even reinstalled windows 10, if any kind soul could help I would really appreciate it I don`t want to have to go back to the alternative.
PS I was uploading to a ESP32 which again I have done a hundred time before
Thank you in advance
Andrew

I had the same problem and took some head banging to resolve:
Platform IO should find the port automatically so no need edit ini file.
The problem turned out to be that a driver is required to convert USB to serial.
Go to Silicon Labs website and download the generic driver for CP210x and follow the installation instructions.
Platformio should now be able to find the port.
Good luck!

Ditto, same problem and same error message - even down to the same line numbers - in an installation that’d been running like the proverbial Swiss watch for yonks with ESP32’s on Win 11. As I was about to leap down the ‘let’s get into redoing the drivers and software install’ rabbit hole I had a rare moment of lucidity, c’mon Bruce, try another device. Bingo, problem solved. Rush in slowly is good.
Cheers