【雑学】composer requireで"the requested PHP extension pcntl is missing from your system."のエラーが出た場合...

どーも!

たかぽんです!

今回はlaravelのプロジェクトに対してcomposerで出会ったエラーについてです...!

今回はn+1の検知のためのライブラリを追加したい場合に出たんですが、気になったので調べたので記事にしておこうと思います!

composerのエラー

さて、実際に筆者が出会ったエラーは以下でした。

root@a7bae7c741f2:/work# composer require beyondcode/laravel-query-detector --dev
Using version ^1.4 for beyondcode/laravel-query-detector
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/horizon v4.3.5 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system.
    - laravel/horizon v4.3.5 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system.
    - laravel/horizon v4.3.5 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system.
    - Installation request for laravel/horizon v4.3.5 -> satisfiable by laravel/horizon[v4.3.5].

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/etc/php/php.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-redis.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

composer requireをしようとすると、上記のように"hoge v4.3.5 requires ext-pcntl"と言った感じで"ext-pcntl"が必要だぞー!

って言われてしまいました。

いきなり結論ですが...

これに対応するにはどうやら以下のようにすればいいらしいです。

composer require beyondcode/laravel-query-detector --dev --ignore-platform-reqs

"--ignore-platform-reqs"をつけることで、PHPのextension等をスルーしてくれるそうです。

詳しくは以下で解説されているので、是非ご覧ください...!

requireだけでなく、install等でも同じものが出てくる場合があるので、合わせてオプションをつけてみてください。

まとめ

今回はcomposerでのエラーについて書きました...!

割と前々からちょくちょく引っかかってはいたんですが、毎回なんだっけなー?

と調べていたので...

今回まとめたので今後は困らなそうです...!

もし困ったら皆さんも試してみてくださいね...!

それでわ!

おすすめの記事