How to fix Composer error: "could not scan for classes inside dir"?

Viewed 61108

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?

13 Answers

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.

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.

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

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

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.

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.

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".

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"
  }
Related