欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Composer 更新时报错:PHP Fatal error:  composerRequireac6b4…(): Failed opening required ‘…/src/helpers.php

程序员文章站 2024-03-24 13:42:52
...

错误汇总

Could not scan for classes inside "D:\Code\project\vendor/smarty/smarty/libs/" which does not appear to be a file nor a folder

'D:\Code\project/vendor/composer/tmp-973d3e9dbc666fef3952c17d41b99a9b' is not a zip archive.

PHP Fatal error:  composerRequireac6b44eedc50f3bd79d92b906ff545c6(): Failed opening required 'D:\Code\project\vendor\composer/../encore/laravel-admin/src/helpers.php' 

 

今天在执行composer update的过程中连续出现几个错误,在这记录下解决过程

错误产生

同事升级了项目中使用的laravel-admin依赖,更新到git,我pull下来后执行composer update进行依赖更新;报错如下:

PHP Fatal error:  composerRequireac6b44eedc50f3bd79d92b906ff545c6(): Failed opening required 'D:\Code\project\vendor\composer/../encore/laravel-admin/src/helpers.php' (include_path='.;C:\php\pear') in D:\Code\project\vendor\composer
\autoload_real.php on line 71

 

解决过程

第一时间想到的是,是不是缓存原因造成的,因此执行composer clearcache清除缓存操作

D:\Code\project>composer clearcache
Cache directory does not exist (cache-vcs-dir): 
Clearing cache (cache-repo-dir): C:\Users\lauwen\AppData\Local\Composer\repo
Clearing cache (cache-files-dir): C:\Users\lauwen\AppData\Local\Composer\files
Clearing cache (cache-dir): C:\Users\lauwen\AppData\Local\Composer
All caches cleared.

 

清除完缓存后,再次更新还是出现相同错误,因此把vendor目录删掉重新,执行composer install重新安装所有依赖,安装过程出现新错误:

[UnexpectedValueException]                                                                    
  'D:\Code\project/vendor/composer/tmp-973d3e9dbc666fef3952c17d41b99a9b' is not a zip archive. 

 

再次执行安装命令,出现下面错误,之后重新执行安装更新都出现同一错误

[RuntimeException]                                                                                                              
  Could not scan for classes inside "D:\Code\project\vendor/smarty/smarty/libs/" which does not appear to be a file nor a folder

 

解决方案

最后,把项目根目录下的composer.lock文件删掉,重新执行composer install进行安装,安装成功!

 

原因分析

错误产生原因应该是我的composer版本过高,与同事们的版本不一致导致的,我的composer版本是2.0.4,两者产生的composer.lock文件是有差别的。主要差别如下图,2.0版本会多了一些support和funding

Composer 更新时报错:PHP Fatal error:  composerRequireac6b4…(): Failed opening required ‘…/src/helpers.php

 

建议

建议在项目提交git过程中应当在.gitignore中设置忽略composer.lock文件