Search code examples
phpsymfonyentity

"src/Entity/Order.php): failed to open stream: No such file or directory" - When make:entity - Symfony 5


I was having this issue in Symfony 5 :

src/Entity/Order.php): failed to open stream: No such file or directory

when I tried to

make:entity

and Order, was going to be the name of my new entity.


What is causing the issue ?

I manually deleted an Entity named Order, a few days ago, from my Project because it didn't satisfy my needs back at the time. The Symfony application tries to autoload the old entity called Order (of which it kept track), but it doesn't exist since I deleted it. This prevents me from (re)creating a clean Order entity now.

What did I manually delete ?

  1. Entity
  2. Repository
  3. Crud Controller in EasyAdmin (+ everything linked to this entity)

What did I try ?

  1. Searching in VSC for Order.php files
  2. php bin/console make:entity --overwrite (to try and overwrite my Order entity)
  3. php bin/console cache:clear

Solution

  • What solved the issue ?

    Running a :

    composer dump-autoload

    A few seconds later, I was able to recreate an entity named Order without any issue. Why ? Because this command line asks Symfony to reload the classes inside the vendor directory and regenerate autoloaded files. Now that it "refreshes" the classes, it does not detect my old Order entity that must have been "cached" insided the autoload. (correct me if I explained it wrong, please)

    Special thanks :

    Retrieving infos from another stackOverflow post. You may find it here : symfony make:entity crash on new project , I simply answered my own question to help others find a solution, faster, in the future.