Search code examples
composer-phpmacos-high-sierrasymfony4

Fatal error while creating Symfony 4 project


after running

     composer create-project symfony/website-skeleton my-project

I get an error :

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  
!!  Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "FileResource" from namespace "App".
!!  Did you forget a "use" statement for "Symfony\Component\Config\Resource\FileResource"? in /Users/bastiennicolau/Documents/dev_web/my-project/src/Kernel.php:39
!!  Stack trace:
!!  #0 /Users/bastiennicolau/Documents/dev_web/my-project/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(80): App\Kernel->configureContainer(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Object(Symfony\Component\Config\Loader\DelegatingLoader))
!!  #1 [internal function]: App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!!  #2 /Users/bastiennicolau/Documents/dev_web/my-project/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(38): call_user_func(Object(Closure), Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!!  #3 /Users/bastiennicolau/Documents/dev_web/my-project/vendor/symfony/config/Loader/Deleg in /Users/bastiennicolau/Documents/dev_web/my-project/src/Kernel.php on line 39
!!  

I've tried some things like changing the psr-4 value in composer.json, and still having the same error after running cache:clear...

What would you do to make it work ? Thanks.


Solution

  • You can try to fix this by opening src/Kernel.php and then go to line 39.

    Delete "FileResource" and then start typing it again. Your IDE (assuming PHPStorm) will suggest that you use FileResource from: Symfony\Component\Config\Resource\FileResource;

    This should be automatically added in the top of Kernel.php.

    Accept that and run composer update. The issue should be resolved.

    Best, Vess