1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

composer installまたはcreate-project実行時、Failed to open stream などのエラーが発生する件の解決方法

Last updated at Posted at 2022-02-18

どのような問題か?

  • composer install
  • composer create-project

などを実行する際に、「Failed to open stream: No such file or directory」「class not found」「Plugin initialization failed」などのエラーが発生し、正常に完了しない。

結論

If you experience failed to open stream: No such file or directory or Plugin initialization failed or class not found type of issue, and are using VirtualBox / Vagrant, this is caused by the VirtualBox filesystem being buggy and not allowing access to the files right after they have been written (https://www.virtualbox.org/ticket/8761).

(意訳)あんたが「failed to open stream: No such file or directory」とか「Plugin initialization failed」とか「class not found」的なエラーに遭遇してて、しかもVirtualBox / Vagrant 環境を使ってるなら、VirtualBoxのファイルシステムのバグが原因かもやで。なんか、ファイル書き込んだ直後にアクセスできないんよ、このバグチケ見てな https://www.virtualbox.org/ticket/8761

※ググり方の問題なのか、日本語の情報が全然出てこなかった。

対応方法

unzipした直後に解凍したファイルにアクセスできないが、ちょっと遅らせれば大丈夫、ということのようです(なんじゃそりゃ・・・)具体的には、

  • /usr/local/bin/unzip を作成
  • 内容を以下のような内容に編集
#!/bin/sh

/usr/bin/unzip "$@"
sleep 0.2

するとうまく行きます。

詳細は、前掲のissue上の下記のコメントを参照してください。
https://github.com/composer/composer/issues/9627#issuecomment-778420647

また、使ってるLinuxディストリビューションや環境によっても若干変わってきそうですが、私の環境では
https://github.com/composer/composer/issues/9627#issuecomment-780471799
こっちで成功しました。

現象(例)

  • composer install する時にcomposer plugin がどーのこーの、とwarning が出る(これ自体は直接関係ない)
 composer/package-versions-deprecated contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "composer/package-versions-deprecated" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
  • 上記の警告に対して y を選択して続行するが、file not found などと言われてcomposer pluginのインストールがskipされてしまう。(これも直接は関係ない)
Skipped installation of bin bin/composer-require-checker for package maglnet/composer-require-checker: file not found in package
  • おかしいなー、と思ってvendor以下とcomposer.lockを削除し、composer.jsonの内容でinstallし直すとエラーが発生する(本件に起因する問題)
composer.json
{
    "require": {
        "maglnet/composer-require-checker": "*" ,
        "php-parallel-lint/php-parallel-lint": "*",
        "phpmd/phpmd": "*",
        "phpmetrics/phpmetrics": "*",
        "phpunit/phpcov": "*",
        "phpunit/phpunit": "*",
        "rarst/phpcs-cognitive-complexity": "*",
        "squizlabs/php_codesniffer": "*",
        "vimeo/psalm": "*",
        "dealerdirect/phpcodesniffer-composer-installer": "*"
    },
    "config": {
        "allow-plugins": {
            "composer/package-versions-deprecated": true,
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    }
}

発生するエラーはこんな感じ。

(中略)
Install of composer/package-versions-deprecated failed

[ErrorException]
include(/var/opt/php/qa/vendor/composer/package-versions-deprecated/src/PackageVersions/Installer.php): Failed to open stream: No such file or directory
  • 上記とは別に、 composer create-project でwordpress環境を構築しようとするとエラーが発生する。(本件に起因する問題)
# 問題が発生するコマンド
composer create-project roots/bedrock ./
(中略)
Executing async command (CWD): '/usr/bin/unzip' -qq '/var/www/html/vendor/composer/tmp-a9780c22e270ec24d1a7f2c06fd63327' -d '/var/www/html/vendor/composer/6e61d5aa'
Executing async command (CWD): rm -rf '/var/www/html/vendor/composer/6e61d5aa'
Plugin initialization failed (include(/var/www/html/vendor/composer/installers/src/Composer/Installers/Plugin.php): Failed to open stream: No such file or directory), uninstalling plugin
  - Removing composer/installers (v2.0.1)
Executing async command (CWD): rm -rf '/var/www/html/vendor/composer/installers'
    Install of composer/installers failed
Downloading https://packagist.org/downloads/
[201] https://packagist.org/downloads/
Reading ./composer.json (/var/www/html/composer.json)
Loading config file ./composer.json (/var/www/html/composer.json)
Failed to initialize global composer: Composer could not find the config file: /root/.composer/composer.json



  [ErrorException]
  include(/var/www/html/vendor/composer/installers/src/Composer/Installers/Plugin.php): Failed to open stream: No such file or directory
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?