Web3 1.0とか、Truffle 5をnpmでインストールする場合、Windowsだとうまくできないことが多い。
たぶんこんなエラーが出てくると思う。Python executableが無いというエラー。
$ npm i web3
> tiny-secp256k1@1.0.1 install \node_modules\tiny-secp256k1
> node-gyp rebuild
\node_modules\tiny-secp256k1>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:153:21)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd \node_modules\tiny-secp256k1
そういう時は、windows-build-tools
を使うと解消するかもしれません。
Powershellを管理者モードで立ち上げ、以下のコマンドを実行。
npm install --global windows-build-tools
Python2.7のほか、なんかいろいろインストールされます。
web3 0.20.6とか、truffle 4.1.15とかならこの手のエラーにはひっかかりません。