41

I'm trying to install composer in terminal by entering this command:

php composer.phar install

it starts to install required packages but I'm getting this error type:

[RuntimeException]
Could not scan for classes inside "app/commands" which does not appear to be a file nor a folder

How can I overcome this issue?

Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
user3026894
  • 463
  • 1
  • 4
  • 8

13 Answers13

47

Usually this happens when you have some corrupted files or any composer update has crashed or interrupted.

To solve, just delete the vendor folders and run composer install

albanx
  • 6,193
  • 9
  • 67
  • 97
  • 5
    This does not always work. I am getting `/vendor/seb astian/diff/src/" which does not appear to be a file nor a folder` error and delete vendor and re-running `composer install` does not work. The original solution of manually adding the folder does. The problem is that my CI validator dies in github because of this problem. Very annoying. – RyanNerd May 08 '17 at 21:05
  • Have you try to delete the vendor folder? – albanx May 09 '17 at 12:57
  • 2
    NOTE: Emptying the folder is not enough, gotta delete the folder itself. Happened to me. – Tom Roggero Feb 12 '18 at 23:45
  • 6
    I use both method, `composer clearcache && rm -rf vendor && composer install` everything works again – kl3sk Dec 12 '19 at 11:22
  • 2
    Thanks @kl3sk but even with all that, it does not seem to be working for me – Benjamin John Mar 31 '20 at 18:51
  • This answer is possible, however this happens because you are missing files, or an update to the module has removed those files- and they are still defined to be autoloaded in your composer.json file. One or the other. I provide a detailed answer, in my answer on this page. – KazaJhodo Feb 05 '21 at 22:30
  • Agree, this was the best way to fix a similar problem on my project. – MRodrigues Dec 13 '21 at 09:38
17

When you install Laravel it creates a

app/commands

folder. Looks like it's not there. Just create it or remove from composer.json:

"classmap": [
    "app/commands",  /// <--- this line
],

And run

composer update
artisan dump-autoload

The last one is similar to composer dump-autoload, but it does some Laravel stuff too.

If you don't have any commands you don't really need it. If you plan to create artisan commands, create that folder and it should work.

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • Laravel has a .gitkeep file there. But as an empty folder should work too. – Antonio Carlos Ribeiro Dec 15 '13 at 15:04
  • Package "artisan" listed for update is not installed. Ignoring. Package "dump-autoload" listed for update is not installed. Ignoring. – user3026894 Dec 15 '13 at 15:20
  • This is actually wrong. Although correct in other situations. In the op case he has the classmap defined, he is missing to what it points. 'app/commands' is either needed- meaning the op is missing files, or has been removed and is still in the installs composer.lock file and should be removed. – KazaJhodo Feb 05 '21 at 22:28
3

I had the same problem. In my case, I noticed that there was no app/commands folder in my laravel install. I created the commands folder and composer dump-autoload was working again!

Saroj
  • 1,088
  • 11
  • 16
  • 1
    If you check out your project from a version control system often the apps/commands folder gets lost. You have to manually recreate it on your local dev machine. – Peter Drinnan Feb 26 '15 at 17:32
  • This will resolve the error, but perhaps not fix the actual problem. In the case of the op I think this will fix it. This error can also happen if an autoloader is in your composer.lock file, and a newer version of the module no longer uses that autoloader. In which case, reference my answer. – KazaJhodo Feb 05 '21 at 22:24
3

You should be able to solve this issue by simply running:

rm -rf vendor/autoload.php vendor/autoload_runtime.php vendor/composer && composer install

This cleans up the corrupted files without having to remove the entire vendor folder or cleaning up the global cache.

As others have mentioned, this usually happens if you interrupt a running Composer (e.g., Ctrl+C during composer update). But it does not corrupt all of the files, only the composer internals – which the command above then removes.

This is an older question with valid answers, but somebody might find this helpful.

Jan Bradáč
  • 195
  • 3
  • 10
1

My problem was that I've had App instead of app in my directory path. Maybe this will help someone.

Justin
  • 901
  • 8
  • 11
0

I am Xampp user on Windows 10. I try all of the above methods but none of them work for me. I fixed my problem with this method, and Hopefully, it will help others.

  1. Create a directory C:\bin
  2. Append ;C:\bin to your PATH environment variable (related help)
  3. Download https://phar.phpunit.de/phpunit-5.7.phar and save the file as C:\bin\phpunit.phar
  4. Open a command line (e.g., press Windows+R » type cmd » ENTER)
  5. Create a wrapping batch script (results in C:\bin\phpunit.cmd):

    C:\Users\username> cd C:\bin
    C:\bin> echo @php "%~dp0phpunit.phar" %* > phpunit.cmd
    C:\bin> exit
    
  6. Open a new command line and confirm that you can execute PHPUnit from any path:

    C:\Users\username> phpunit --version
    PHPUnit x.y.z by Sebastian Bergmann and contributors.
    

This method solves my problem. Hope It will save your day too.

NomanJaved
  • 1,324
  • 17
  • 32
0

I had the same issue. For me it happened after I deleted a class dir and forgot to update composer.json.

The fix was simply updating the classmap array in composer.json

Lando Ke
  • 139
  • 1
  • 5
  • This is also correct, although it doesn't really address how to fix with any sort of detail. If you know what he means, it would get you there. – KazaJhodo Feb 05 '21 at 22:20
0

I think it happens because composer cache error. Try to clear its cache:

composer clearcache

then run the installer again

composer create-project --prefer-dist laravel/laravel blog
0

It generally happens when composer is unable to autoload classmap. Check whether the location to the file or folder is correct.

rakesh shrestha
  • 1,335
  • 19
  • 37
0

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": "dufuz@php.net"
                },
                {
                    "name": "Greg Beaver",
                    "email": "cellog@php.net"
                }
            ],
            "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.

KazaJhodo
  • 86
  • 1
  • 5
-1

Here is another debugging idea:

I accidentally added the vendor/ folder to my repository which then got deployed. After removing it from the repository, the error message composer RuntimeException Could not scan for classes inside polyfill-php80/Resources/stubs which does not appear to be a file nor a folder disappeared.

johnrbnz
  • 357
  • 2
  • 8
-1

in most of cases it is happen because of copy or cloning so try to remove or rename VENDOR folder from the magento installation and rerun "composer install".

Yuriy
  • 69
  • 2
-1

In my case, I was installing wordpress plugins by composer, especially yoast (wordpress-seo) and woocommerce from packagist.org. I changed the sources to wpackagist and it started to work ok:

  "require": {
    "wpackagist-plugin/wordpress-seo": "dev-trunk",
    "wpackagist-plugin/woocommerce": "dev-trunk"
  }
PHZ.fi-Pharazon
  • 1,479
  • 14
  • 15