I'm getting Class 'PackageVersions\Versions' not found after running php artisan

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Solving the Mystery: Why 'Class 'PackageVersions\Versions' Not Found Appears After composer update in Laravel

As a senior developer, I’ve seen countless frustrating errors crop up during dependency management. One of the most confusing ones is when Composer successfully updates packages, yet running an Artisan command immediately results in a fatal error related to missing classes, like the one you are encountering: Class 'PackageVersions\Versions' not found.

This issue usually signals a deep-seated problem with Composer’s autoloading mechanism or a version conflict within your project’s dependencies, especially when dealing with slightly older Laravel setups or specific PHP versions. Let’s dive into why this happens and how we can reliably fix it.

Understanding the Error Context

You are running into an error during the execution of the post-autoload-dump event triggered by Artisan commands like package:discover. This event is responsible for scanning and registering all discovered package namespaces, which rely heavily on Composer's generated autoloader files.

The missing class, PackageVersions\Versions, suggests that a specific component responsible for tracking or defining package versions within the autoload structure has either been corrupted, improperly loaded, or is incompatible with the current state of your installed packages and PHP environment (PHP 7.4 in your case).

Your provided context—Laravel 5.8, Composer 2.3.2, and specific dependencies like laravel/framework—points towards a potential incompatibility between how older Laravel components interact with newer Composer versions or system configurations.

Step-by-Step Troubleshooting Guide

Don't panic. This is almost always resolvable by following a systematic cleanup process.

1. The Essential Cleanup

The first and most effective step is to force Composer to regenerate all autoload files from scratch, ensuring everything is correctly indexed.

Run these commands in your project root:

# 1. Clear the existing autoloader cache
composer dump-autoload -o

# 2. Reinstall dependencies (to ensure a fresh state)
composer install

If the issue persists, try running a full update again, focusing on resolving potential conflicts:

composer update --no-scripts

The --no-scripts flag prevents Composer from executing scripts during the update phase, which can sometimes bypass problematic execution flows that trigger the error. If this works, it confirms the issue lies specifically within the post-autoload scripts execution related to package:discover.

2. Environment and Version Check

Since you are on macOS and using PHP 7.4, ensure your environment is completely clean. Sometimes, residual files or old Composer cache data interfere with the process.

  • Check PHP Compatibility: While Laravel 5.8 generally supports PHP 7.4, confirm that all installed packages are fully compatible with this version. If you were planning an upgrade, checking the official Laravel release notes regarding PHP requirements is crucial—this aligns with the robust ecosystem focus seen on platforms like laravelcompany.com.
  • Composer Version: While Composer 2.3.2 is functional, ensuring you are running a recent stable version of Composer (or using a tool like Composer's built-in updater) can sometimes resolve underlying dependency resolution issues that lead to these autoloading errors.

3. Deeper Dependency Investigation

If the basic steps fail, investigate your composer.json file closely. Look at the versions you specified for core packages (laravel/framework, laravel/tinker). If any of these are pinned too strictly or if there are conflicting transitive dependencies (dependencies of dependencies), it can cause autoloading failures during discovery.

A good practice is to review your requirements and ensure they align with current best practices, especially when working within the Laravel framework ecosystem.

Conclusion: Maintaining a Healthy Development Environment

The error Class 'PackageVersions\Versions' not found is a symptom of an environmental hiccup rather than a bug in your application code itself. By treating it as a dependency management problem—cleaning caches, forcing re-installation, and verifying the environment—you can resolve these frustrating errors quickly.

Remember, maintaining a clean state for your dependencies is paramount. Always prioritize robust autoloading and dependency resolution when working on any modern PHP project. Stick to these systematic steps, and you’ll be back to developing Laravel applications smoothly in no time!