Ethereum
web3.js

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

> scrypt@6.0.3 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


> scrypt@6.0.3 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! scrypt@6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the scrypt@6.0.3 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 fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "ganache-cli > webpack-cli@2.0.14" 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 node-gyp@3.6.2
gyp info using node@8.11.1 | 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