💭

「npm ERR! gyp info using node-gyp@8.3.0」が発生したときの調査・対処法

2022/02/16に公開

概要

node を v14 から v16 にする作業をしていました。
そのとき、コンテナのビルドでエラーが発生したので、自分が実施した解決策をまとめます。

npm ERR! DIRECTORY/node_modules/bindings/bindings.js:135
npm ERR!   throw err;npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.3.0
npm ERR! gyp info using node@16.13.2 | linux | x64
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
npm ERR! gyp ERR! find Python checking if "python3" can be used
npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if "python" can be used
npm ERR! gyp ERR! find Python - executable path is "/usr/bin/python"
npm ERR! gyp ERR! find Python - version is "2.7.5"
npm ERR! gyp ERR! find Python - version is 2.7.5 - should be >=3.6.0
npm ERR! gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python You need to install the latest version of Python.
npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
npm ERR! gyp ERR! find Python you can try one of the following options:
npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
npm ERR! gyp ERR! find Python   (accepted by both node-gyp and npm)
npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
npm ERR! gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
npm ERR! gyp ERR! find Python For more information consult the documentation at:
npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Python installation to use

略

対処法

コンテナの Python のバージョンが合わないエラーのようです。
以下の方の記事でも、似たような問題が発生していたようです。

https://zenn.dev/media_engine/articles/updated-nodejs-from-v12-to-v16#gypが動かない問題

他にも事情があり、コンテナのイメージを変更できませんでした。
そこで、Python を使用しているパッケージの調査をしました。
エラーログをみるとbindings.jsが依存しているそうです。
npm installしたパッケージではないので、さらに依存しているパッケージを探しました。

> npm ls bindings
DIRECTORY@1.0.0 /PATH/TO/DIRECTORY
└─┬ vue-jest@3.0.7
  └─┬ deasync@0.1.24
    └── bindings@1.5.0

vue-jest@3.0.7が依存していました。
このような OS レベルの依存の問題があったので、vue-jest@3.0.7側も対策していないかと考え、最新版にしました。

> npm install vue-jest@latest

再度確認します。
参照しなくなったことがわかりました。

> npm ls bindings
DIRECTORY@1.0.0 /PATH/TO/DIRECTORY
└── (empty)

あとは、同様にビルドをしたら最後まで実行されました。
今回の例では、パッケージを最新にするだけで、依存が減ってビルドエラーが発生しなくなりました。
似たような状況が発生したら検証してみてください。

Discussion