Table of Contents
If you’re working with Magento 2 and see an error like this:
Warning: require(/var/www/html/M243/vendor/composer/../magento/module-contact/registration.php): failed to open stream: No such file or directory in /var/www/html/M243/vendor/composer/autoload_real.php on line 73Fatal error: require(): Failed opening required ‘/var/www/html/M243/vendor/composer/../magento/module-contact/registration.php’ (include_path=’/var/www/html/M243/vendor/magento/zendframework1/library:.:/usr/share/php’) in /var/www/html/M243/vendor/composer/autoload_real.php on line 73Do not panic — this is a common issue, and it’s usually easy to fix.
This error usually means that Magento can’t find the files it needs to load your code properly. These files are part of the vendor directory, where Composer installs all the PHP dependencies Magento needs to run.
Why Does This Error Happen?
Below are the most common reasons:
- The vendor folder is missing or incomplete
- Composer files are corrupted or not generated properly
- Magento is not installed properly
- You cloned the project but didn’t run composer install
- The autoload files are missing or corrupted
Quick Fix: Try This First
Before you proceed, check if the vendor folder exists in your Magento root directory or not.
If it does exist, try running this command:
composer dump-autoload
This tells Composer to rebuild the autoloader files, which should fix missing file errors like the one we are seeing: “Failed to open stream: No such file or directory in vendor/composer/autoload_real.php”.
Then run:
php bin/magento setup:upgradephp bin/magento setup:di:compilephp bin/magento cache:flushCheck if the error is gone. If not, move on to the next method.
Full Fix: Reinstall Vendor Folder
If the composer dump-autoload command didn’t work, or if the vendor folder is missing or broken, follow these steps:
Step 1: Delete the vendor folder and composer.lock file
rm -rf vendorrm composer.lockThis removes any corrupted or partial dependencies.
Step 2: Reinstall all Composer packages
Now run:
composer installThis downloads and installs all needed dependencies into a new vendor folder.
Step 3: Recompile and Clear Cache
Once Composer finishes, execute these Magento commands:
php bin/magento setup:upgradephp bin/magento setup:di:compilephp bin/magento cache:flushTips to Prevent This in the Future
- Always run composer install after cloning a project or switching branches
- Don’t manually modify files in the vendor folder
- Make sure your .gitignore includes the vendor/ directory (Magento best practice)
- If you ever relocate or restore your Magento site, always reinstall dependencies with Composer
Summary
| Problem | Solution |
| Autoload file missing but vendor/ exists | Run composer dump-autoload |
| vendor/ folder is missing or broken | Delete vendor/ and composer.lock, then run composer install |
| Still getting errors | Recheck file permissions and Magento version compatibility |
By following these steps, you should be able to have your Magento 2 site up and running again without that annoying “Failed to open stream: No such file or directory” error.