PHP Intelephense does not recognize PHPMailer and PhpSpreadsheet in Visual Studio Code (VS Code) project
I have been working on a project for months now and all worked just fine. But now I am suddenly experiencing error in my IDE (Visual Studio Code) produced by PHP Intelephense showing:
> Undefined type 'PHPMailer\PHPMailer\PHPMailer'
> Undefined type 'PhpOffice\PhpSpreadsheet\Spreadsheet'

I imagine the error must be somehow PHP Intelephense related because I can execute the PHP project without errors and both PHPMailer and Spreadsheet works fine. However, I am frustrated for the IDE errors, which do not exist.
I have tried all this but no success:
- Project structure: file composer.json and directory vendor are both in the same (project) directory;

- Composer Autoload File: PHP files include the Composer autoload file at the top

- Clear and Restart Intelephense: Open the Command Palette (Ctrl+Shift+P) and run 'Intelephense: Index workspace' and than Restart VS Code.
- Regenerate the autoload files: in your project's home directory run 'composer dump-autoload'
- Verify Package Installation: in your project's home directory run 'composer show phpmailer/phpmailer' and 'composer show phpoffice/phpspreadsheet'
- Reinstall PHP Intelephense extension in VS code
- Create a fresh project: As a last resort, I have created a new project to see if the issue persists.
Create a new directory for the project.
Initialize Composer and install the packages:
None of that solved the issue in my case.