Fatal error: Uncaught ReflectionException: Class config does not exist
This specific stack trace indicates a fundamental mismatch between your application's structure and the Laravel framework's expectations. The error Fatal error: Uncaught ReflectionException: Class config does not exist occurs because the Illuminate\Container\Container class attempts to instantiate a service using the string 'config'. It assumes that this string corresponds to an existing class in your autoloading namespace, but it cannot find one.
This behavior is almost exclusively caused by running laravel new or php artisan install:api inside an existing directory that already contains a valid Laravel installation. When you execute these commands on a populated folder, the CLI tool generates a brand new composer.json. This new file defines a set of autoload namespaces and PSR-4 paths that conflict with the classes already present in your project's app, config, and database directories.
Specifically, the error happens during the post-autoload-dump event triggered by composer dump-autoload. The fresh autoloader tries to resolve dependencies based on the new configuration, but because the old namespaces are still physically present, the resolver gets confused about where classes like ConfigServiceProvider or similar bootstrap files belong. The framework ends up looking for a class literally named config (or expecting one to be registered under that handle) and fails.
You mentioned cloning a repository from GitHub. This scenario often happens when a project's .gitignore is missing or misconfigured, allowing the vendor/ directory to be committed to version control. If your Git history contains a mix of old vendor dependencies and new composer.json entries generated by a fresh install command, you will encounter this exact reflection error. The autoloader cannot reconcile the two states.
To resolve this, you must ensure that the project's dependency definition matches its actual file structure. Do not run installation commands on directories that already contain vendor/, app/, or config/ unless you intend to discard them. If you need to reset the project state, follow these steps:
- Remove the existing
vendorfolder and thecomposer.lockfile.rm -rf vendor composer.lock - Check your
composer.json. Ensure it does not contain conflicting autoload paths generated by a previous "new" command attempt. If you see entries pointing to non-existent directories, remove them or align them with your current folder structure. - Run the installation commands again:
composer install --no-dev php artisan config:clear php artisan cache:clear
The composer install command rebuilds the autoloader based on the current composer.json. The php artisan config:clear command ensures that Laravel doesn't try to load cached configuration bindings that might reference classes from a previous, incompatible build.
If you are working with an existing codebase and simply want to revert to a stable state, ensure your .gitignore file includes vendor/, .env, and any generated files like .phpunit.result.cache. Committing these artifacts can lead to merge conflicts or the very scenario described in the error logs.
In some cases, if you have modified the composer.json manually to add custom autoload entries, double-check that those paths exist on your filesystem. A common pitfall is creating a namespace entry like "App\\Config": "app/config" but then having Laravel 5.8 expect the service provider to be located in a different place. The framework relies heavily on standard directory conventions; deviating without updating the autoloader configuration leads to ReflectionException errors when trying to instantiate missing classes.
For developers managing multiple environments, it is crucial to verify that your local installation matches the production structure before running artisan commands that trigger autoload generation. If you are using a platform like LaravelCompany.com for hosting or deployment, ensure their deployment scripts do not inadvertently run laravel new on an existing codebase. Always inspect the generated composer.json after any installation script runs to confirm it reflects your project's actual class hierarchy.