This happens due to your composer.lock file.
For instance in my case I was getting:
Could not scan for classes inside ".../vendor/drupal/core-composer-scaffold/PEAR/" which does not appear to be a file nor a folder
That directory indeed did not exist. However, search for 'PEAR' inside of your composer.lock... 'app/commands' in this case- and you will find the modules definition:
{
"name": "drupal/core-composer-scaffold",
"version": "8.9.11",
"source": {
"type": "git",
"url": "https://github.com/drupal/core-composer-scaffold.git",
"reference": "c902d07cb49ef73777e2b33a39e54c2861a8c81d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/drupal/core-composer-scaffold/zipball/c902d07cb49ef73777e2b33a39e54c2861a8c81d",
"reference": "c902d07cb49ef73777e2b33a39e54c2861a8c81d",
"shasum": ""
},
"require": {
"php": ">=4.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "class",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"PEAR/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"."
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Helgi Thormar",
"email": "[email protected]"
},
{
"name": "Greg Beaver",
"email": "[email protected]"
}
],
"description": "The PEAR Exception base class.",
"homepage": "https://github.com/pear/PEAR_Exception",
"keywords": [
"exception"
],
"time": "2019-12-10T10:24:42+00:00"
},
Our important piece is:
"autoload": {
"classmap": [
"PEAR/"
]
},
Composer is attempting to autoload from that directory, which is why you get a composer crash- that directory doesn't exist. Likely the same thing in your case of 'app/commands'.
Remove the entire package from your composer.lock- which for clarity is the longer code posting above. Then rerun your 'composer require' for that package. Example: composer require drupal/core-composer-scaffold
.
In my case I needed a specific version, the default would give me version 9, I needed 8. My command was composer require drupal/core-composer-scaffold:^8
.
Once this is done your composer install will run without a hitch.