Ethereum: web3やweb3-ethをインストールする時にnode-gypのエラーが出る


環境により、web3.jsやweb-eth等のパッケージをインストールする際にエラーが発生する場合があります。私はUbuntu 16.04で発生しました。

結論

先に build-essential をインストールする。

sudo apt-get install build-essential

これを入れることで、web3等のインストール時もエラーは発生しなくなりました。

環境

  • Ubuntu 16.04 LTS

エラー内容

叩いたコマンドとエラー内容は以下のとおりです。

root@ip-10-1-0-xx:/var/contracts# npm i --save web3-eth

> [email protected] preinstall /var/contracts/node_modules/scrypt
> node node-scrypt-preinstall.js

Error: Error: Command failed: ./configure
configure: error: in `/var/contracts/node_modules/scrypt/scrypt/scrypt-1.2.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details


> [email protected] install /var/contracts/node_modules/scrypt
> node-gyp rebuild

make: Entering directory '/var/contracts/node_modules/scrypt/build'
  SOLINK_MODULE(target) Release/obj.target/copied_files.node
make: g++: Command not found
copied_files.target.mk:22: recipe for target 'Release/obj.target/copied_files.node' failed
make: *** [Release/obj.target/copied_files.node] Error 127
make: Leaving directory '/var/contracts/node_modules/scrypt/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.4.0-1041-aws
gyp ERR! command "/root/.ndenv/versions/v8.11.1/bin/node" "/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/contracts/node_modules/scrypt
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-05-02T05_23_21_295Z-debug.log


root@ip-10-1-0-xx:/var/contracts# yarn add web3-eth
yarn add v1.6.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "ganache-cli > [email protected]" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
[1/3] ⠄ sha3: gyp info spawn args   '-Goutput_dir=.' ]
[2/3] ⠄ websocket: CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
[3/3] ⠄ scrypt
[-/3] ⠄ waiting...
error /var/contracts/node_modules/sha3: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /var/contracts/node_modules/sha3
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/var/contracts/node_modules/sha3/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.node-gyp/8.11.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/8.11.1',
gyp info spawn args   '-Dnode_gyp_dir=/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/8.11.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/var/contracts/node_modules/sha3',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/var/contracts/node_modules/sha3/build'
  CXX(target) Release/obj.target/sha3/src/addon.o
make: g++: Command not found
sha3.target.mk:99: recipe for target 'Release/obj.target/sha3/src/addon.o' failed
make: *** [Release/obj.target/sha3/src/addon.o] Error 127
make: Leaving directory '/var/contracts/node_modules/sha3/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.4.0-1041-aws
gyp ERR! command "/root/.ndenv/versions/v8.11.1/bin/node" "/root/.ndenv/versions/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/contracts/node_modules/sha3

Redhat系の場合

CentOSやAWS Linuxなど、Redhat系では以下で解決。参考

sudo yum groupinstall "Development Tools"

エラーは以下の通り。

yarn install v1.6.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > @johmun/[email protected]" has unmet peer dependency "[email protected]".
warning "@nuxtjs/markdownit > [email protected]" has unmet peer dependency "webpack@^4.3.0".
warning "babel-jest > babel-preset-jest > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning " > [email protected]" has unmet peer dependency "vue@^2.0.0".
warning " > [email protected]" has unmet peer dependency "vuex@^2.0.0".
warning " > @vue/[email protected]" has unmet peer dependency "[email protected]".
warning " > @vue/[email protected]" has unmet peer dependency "vue-template-compiler@^2.x".
warning " > [email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning " > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
warning " > [email protected]" has unmet peer dependency "webpack@>=2.0.0 <5.0.0".
warning " > [email protected]" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0".
warning " > [email protected]" has unmet peer dependency "vue@^2.x".
warning " > [email protected]" has unmet peer dependency "vue-template-compiler@^2.x".
[4/4] Building fresh packages...
[1/6] ⢀ sha3: gyp info spawn args   '-Goutput_dir=.' ]
[2/6] ⢀ keccak: > node-gyp rebuild
[3/6] ⢀ secp256k1: > node-gyp rebuild
[4/6] ⢀ scrypt: '-Goutput_dir=.' ]
error /var/frontend-application/node_modules/sha3: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /var/frontend-application/node_modules/sha3
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp http GET https://nodejs.org/download/release/v8.10.0/node-v8.10.0-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v8.10.0/node-v8.10.0-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v8.10.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v8.10.0/SHASUMS256.txt
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/root/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/var/frontend-application/node_modules/sha3/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.node-gyp/8.10.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/8.10.0',
gyp info spawn args   '-Dnode_gyp_dir=/root/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/8.10.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/var/frontend-application/node_modules/sha3',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory `/var/frontend-application/node_modules/sha3/build'
 CXX(target) Release/obj.target/sha3/src/addon.o
make: g++: Command not found
make: *** [Release/obj.target/sha3/src/addon.o] Error 127

make: Leaving directory `/var/frontend-application/node_modules/sha3/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.14.106-79.86.amzn1.x86_64
gyp ERR! command "/root/.nvm/versions/node/v8.10.0/bin/node" "/root/.nvm/versions/node/v8.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/frontend-application/node_modules/sha3