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

1

9

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
Snowblink answered 16/3, 2021 at 18:18 Comment(0)
S
24

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.

Snowblink answered 16/3, 2021 at 18:18 Comment(3)
Glad you got it working but 'composer dump-autoload' just recreates vendor/autoload.php based on the contents of composer.json. Nothing directly relegated to Symfony. I suspect you made other changes after deleting your Order entity though it's difficult to figure out exactly what you did. But again, as long as it works.Naphthyl
Great feedback, thank you. I indeed kept on working on my project until I had to (re)create the Order entity. I wanted to share the different steps and things I tried and shared them to the community. Take care, cheersSnowblink
I had the same issue and dump-autoload solved it. I took a look at vendor/composer/autoload_static.php before doing so and it had all doctrine entities included in $classMap - even the ones that had deleted php files. The make:entity script checks if an entity exists using class_exists(). That check seems to return true until you regenerate $classMap to not contain the removed files/classes. It seems like composer makes classes available even if the files for it don't exist anymore. Which would explain why you can't recreate the entity until you regenerated the classMap using dump-autoload..Pemmican

© 2022 - 2024 — McMap. All rights reserved.