[Solved] Type error: Return value of Symfony\Component\DomCrawler\ Crawler::createSubCrawler() must be an instance of Symfony\Component\DomCrawler\object, instance of Symfony\Component\DomCrawler\Crawler returned
Problem:
I found an error - Type error: Return value of Symfony\Component\DomCrawler\Crawler::createSubCrawler() must be an instance of Symfony\Component\DomCrawler\object, instance of Symfony\Component\DomCrawler\Crawler returned with the laravel fabpot/goutte & FriendsOfPHP/Goutte package
Solution:
First check your php version and then update your php version to v7.3 or higher
In symfony/dom-crawler, version 5.0.0 updated the Crawler::createSubCrawler() method to have an object return type hint. It also updated the PHP version dependency to ^7.2.5, so this version would not get installed unless the version of PHP running composer is >= ^7.2.5.
However, the version of PHP run by the web server does not appear to understand the object type hint, so it is looking for an actual class named Symfony\Component\DomCrawler\object. Since PHP doesn't understand the type hint, that means the version running the code is < 7.2.0.
Packages Link - fabpot/goutte & FriendsOfPHP/Goutte package