Other / 1个月前

记一次 composer 问题的解决过程!!

快下班的时候准备新搞个小项目本地测试,随手就是一个composer

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

结果一个鲜红的错误

[RuntimeException]
  Could not scan for classes inside "/home/vagrant/code/laravel/vendor/sebastian/diff/src/" which does not appear to be a file nor a folder

跑去目录看了下,sebastian/diff 是空的,看来是没有下载完整。

最近composer镜像总是有问题,加上vvv看看吧。 镜像确实走的https://packagist.laravel-china.org,但是laravel的每一个包似乎都在报错,随便放一两个上来,

  - Installing laravel/tinker (v1.0.7): Loading from cache
    Failed to execute unzip -qq  '/home/vagrant/code/laravel/vendor/laravel/tinker/5f049e468f89de34bf7c9b7c9fb2ab5d' -d '/home/vagrant/code/laravel/vendor/composer/7e1d1987'

[/home/vagrant/code/laravel/vendor/laravel/tinker/5f049e468f89de34bf7c9b7c9fb2ab5d]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of /home/vagrant/code/laravel/vendor/laravel/tinker/5f049e468f89de34bf7c9b7c9fb2ab5d or
        /home/vagrant/code/laravel/vendor/laravel/tinker/5f049e468f89de34bf7c9b7c9fb2ab5d.zip, and cannot find /home/vagrant/code/laravel/vendor/laravel/tinker/5f049e468f89de34bf7c9b7c9fb2ab5d.ZIP, period.

    The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
    Unzip with unzip command failed, falling back to ZipArchive class
        - Installing filp/whoops (2.2.0): Loading from cache
    Failed to execute unzip -qq  '/home/vagrant/code/laravel/vendor/filp/whoops/c32bf4145c2a210b5f80b1000ec0ac3c' -d '/home/vagrant/code/laravel/vendor/composer/3ede2c84'

[/home/vagrant/code/laravel/vendor/filp/whoops/c32bf4145c2a210b5f80b1000ec0ac3c]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of /home/vagrant/code/laravel/vendor/filp/whoops/c32bf4145c2a210b5f80b1000ec0ac3c or
        /home/vagrant/code/laravel/vendor/filp/whoops/c32bf4145c2a210b5f80b1000ec0ac3c.zip, and cannot find /home/vagrant/code/laravel/vendor/filp/whoops/c32bf4145c2a210b5f80b1000ec0ac3c.ZIP, period.

    The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
    Unzip with unzip command failed, falling back to ZipArchive class

什么情况?镜像出错了?好吧,去掉镜像,再来看下,

vagrant@homestead:~/code$ composer config -g -l
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https?://repo.packagist.org
[repositories.packagist.org.allow_ssl_downgrade] true

现在用官方镜像试试,SS要开启来。(穷人只有免费试用:joy::joy::joy:) file

结果还是一样!!! 怎么的,今天packagist全挂了?试试安装个扩展包吧

vagrant@homestead:~/code/test$ composer require "overtrue/laravel-wechat"
Using version ^4.0 for overtrue/laravel-wechat
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing overtrue/laravel-wechat (4.0.22): Downloading (100%)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-wechat
Package manifest generated successfully.

FxxK , 什么情况?扩展包可以新项目就不行?百度google全找了下,居然没有!!!! 突然想到每次开homestead都会提醒我的

==> homestead-7: A newer version of the box 'laravel/homestead' for provider 'virtualbox' is
==> homestead-7: available! You currently have version '6.0.0'. The latest is version
==> homestead-7: '6.1.0'. Run `vagrant box update` to update.

OK.我来升级吧,反正没事做就死马当活马医吧... 漫长的等待后...

➜  Homestead git:(860e3cd) vagrant box update
==> homestead-7: Checking for updates to 'laravel/homestead'
    homestead-7: Latest installed version: 6.0.0
    homestead-7: Version constraints: >= 5.2.0
    homestead-7: Provider: virtualbox
==> homestead-7: Updating 'laravel/homestead' with provider 'virtualbox' from version
==> homestead-7: '6.0.0' to '6.1.0'...
==> homestead-7: Loading metadata for box 'https://vagrantcloud.com/laravel/homestead'
==> homestead-7: Adding box 'laravel/homestead' (v6.1.0) for provider: virtualbox
    homestead-7: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/6.1.0/providers/virtualbox.box
==> homestead-7: Box download is resuming from prior download progress
==> homestead-7: Successfully added box 'laravel/homestead' (v6.1.0) for 'virtualbox'!
➜  Homestead git:(860e3cd) vagrant box list
laravel/homestead (virtualbox, 6.0.0)
laravel/homestead (virtualbox, 6.1.0)

现在有两个box了,这里吐槽下virtualbox的升级,明明是update,结果是新加了一个box进来,你在搞笑吗??这逻辑也是棒棒的! vagrant也一起升级了算球。 file

➜  Homestead git:(860e3cd) vagrant version
Installed Version: 2.1.2
Latest Version: 2.1.2

You're running an up-to-date version of Vagrant!

重新来启动homestead吧,又是经过漫长的等待,终于进虚拟机了(新加了一个virtualbox,启动会以最新版本启动,所以初始化比正常启动要慢!)

重新安装个laravel项目,终于看到了熟悉的画面

Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
> @php artisan key:generate
Application key [base64:VlRjk/MdR/KjDJUyJhC1z4FbOL8HqqrFvo5QUbQUogw=] set successfully.

这个小问题终于解决了。

回过头来想一下,是哪里出了问题呢?

不知道,没想明白,那么问题来了:

这和重新安装一个homestead有TM什么区别???

作者: Jourdon

本文地址: https://qiehe.net/posts/remember-a-solution-to-the-composer-problem

转载请注明出处!

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作! 赞赏码