記一次 Composer 問題的解決過程!!

Jourdon發表於2018-08-07

快下班的時候準備新搞個小專案本地測試,隨手就是一個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.

這個小問題終於解決了。

回過頭來想一下,是哪裡出了問題呢?

不知道,沒想明白,那麼問題來了:

作者: Jourdon
本文地址: https://www.qiehe.net/posts/9/remember-a-solution-to-the-composer-problem
轉載請註明出處!

如果覺得我的文章對您有用,請隨意打賞。您的支援將鼓勵我繼續創作!
file

Good Good Study , Day Day Up!!

相關文章