php 如何修复 Composer 错误:“无法扫描目录内的类”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20595801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix Composer error: "could not scan for classes inside dir"?
提问by user3026894
I'm trying to install composer in terminal by entering this command:
我正在尝试通过输入以下命令在终端中安装 Composer:
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
[RuntimeException]
无法扫描“app/commands”中的类,该类既不是文件也不是文件夹
How can I overcome this issue?
我怎样才能克服这个问题?
回答by albanx
Usually this happens when you have some corrupted files or any composer update has crashed or interrupted.
通常,当您有一些损坏的文件或任何 Composer 更新崩溃或中断时,就会发生这种情况。
To solve, just delete the vendor folders and run
composer install
要解决,只需删除供应商文件夹并运行
composer install
回答by Antonio Carlos Ribeiro
When you install Laravel it creates a
当您安装 Laravel 时,它会创建一个
app/commands
folder. Looks like it's not there. Just create it or remove from composer.json:
文件夹。看起来它不在那里。只需创建它或从 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.
最后一个类似于composer dump-autoload,但它也做了一些 Laravel 的东西。
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.
如果您没有任何命令,则您实际上并不需要它。如果您打算创建工匠命令,请创建该文件夹,它应该可以工作。
回答by Saroj
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!
我有同样的问题。就我而言,我注意到我的 Laravel 安装中没有 app/commands 文件夹。我创建了命令文件夹,composer dump-autoload 又开始工作了!
回答by Justin
My problem was that I've had Appinstead of appin my directory path. Maybe this will help someone.
我的问题是我的目录路径中有App而不是app。也许这会帮助某人。
回答by NomanJaved
I am Xamppuser 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.
我是 上的Xampp用户Windows 10。我尝试了上述所有方法,但没有一个对我有用。我用这种方法解决了我的问题,希望它会帮助其他人。
- Create a directory C:\bin
- Append
;C:\binto your PATH environment variable (related help) - Download https://phar.phpunit.de/phpunit-5.7.pharand save the file as
C:\bin\phpunit.phar - Open a command line (e.g., press
Windows+R? typecmd? ENTER) 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> exitOpen 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.
- 创建目录 C:\bin
- 附加
;C:\bin到您的 PATH 环境变量(相关帮助) - 下载https://phar.phpunit.de/phpunit-5.7.phar并将文件另存为
C:\bin\phpunit.phar - 打开命令行(例如,按
Windows+R? typecmd? ENTER) 创建包装批处理脚本(结果为
C:\bin\phpunit.cmd):C:\Users\username> cd C:\bin C:\bin> echo @php "%~dp0phpunit.phar" %* > phpunit.cmd C:\bin> exit打开一个新的命令行并确认您可以从任何路径执行 PHPUnit:
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.
这个方法解决了我的问题。希望它也能拯救你的一天。
回答by Lando Ke
I had the same issue. For me it happened after I deleted a class dir and forgot to update composer.json.
我遇到过同样的问题。对我来说,它发生在我删除了一个类目录并忘记更新 composer.json 之后。
The fix was simply updating the classmap array in composer.json
修复只是更新 composer.json 中的 classmap 数组
回答by Abdul Manaf Saparuddin
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
回答by Rey Young
It generally happens when composer is unable to autoload classmap. Check whether the location to the file or folder is correct.
当 Composer 无法自动加载 classmap 时,通常会发生这种情况。检查文件或文件夹的位置是否正确。

