LoginSignup
6

More than 5 years have passed since last update.

posted at

updated at

[メモ]vagrantでnpm install中に出たエラーまとめ

あまりに特殊なパターンが多すぎて検索しても出てこないため自分用メモ

npm install に失敗するパターン

symlinkに失敗する

実際に出るエラーは以下のような感じ

npm ERR! syscall symlink
npm ERR! EPROTO: protocol error, symlink '../mime/cli.js' -> '/home/vagrant/Code/node_modules/.bin/mime'

原因
Windowsでは共有フォルダ内にsymlinkを貼ることが出来ない。

対処
出来るようにしてもいいが--no-bin-linkフラグをつければそもそもsymlinkを利用しないため通るようになる。

make Releaseに失敗する

ちょっと複雑な行動をするモジュールを導入しようとしたら引っかかった。
具体的には以下のようなエラーが出た。

> make Release

cd worker && /usr/bin/python2 ./scripts/configure.py -R mediasoup-worker
['-R', 'mediasoup-worker', '/home/vagrant/Code/node_modules/mediasoup/worker/mediasoup-worker.gyp', '-I', '/home/vagrant/Code/node_modules/mediasoup/worker/common.gypi', '--depth=.', '-f', 'make', '-Goutput_dir=/home/vagrant/Code/node_modules/mediasoup/worker/out', '--generator-output', '/home/vagrant/Code/node_modules/mediasoup/worker/out', '-Dgcc_version=44', '-Dclang=0', '-Dhost_arch=x64', '-Dtarget_arch=x64', '-Dopenssl_fips=', '-Dmediasoup_asan=false', '-Dnode_byteorder=little']
make BUILDTYPE=Release -C worker/out
make[1]: Entering directory `/home/vagrant/Code/node_modules/mediasoup/worker/out'
  CXX(target) /home/vagrant/Code/node_modules/mediasoup/worker/out/Release/obj.target/jsoncpp/deps/jsoncpp/jsoncpp/bundled/jsoncpp.o
cc1plus: error: unrecognized command line option "-std=c++11"
make[1]: *** [/home/vagrant/Code/node_modules/mediasoup/worker/out/Release/obj.target/jsoncpp/deps/jsoncpp/jsoncpp/bundled/jsoncpp.o] Error 1
make[1]: Leaving directory `/home/vagrant/Code/node_modules/mediasoup/worker/out'
make: *** [Release] Error 2
npm WARN SFUServer@0.0.0 No description
npm WARN SFUServer@0.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! mediasoup@2.0.5 postinstall: `make Release`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the mediasoup@2.0.5 postinstall 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!     /home/vagrant/.npm/_logs/2017-12-13T02_07_27_220Z-debug.log

make ReleaseとはC++系のアプリをビルドするためのアプリケーション(コマンド)らしい。
npm側のエラーが目立っていて分かり辛いがきちんとerror: unrecognized command line option "-std=c++11"と書かれている。
C++については詳しくないためリファレンスサイトを参照
cpprefjp - C++日本語リファレンス

どうやら4.8ならば最新らしい。と当たりをつけて現在導入されているgccのバージョンを見てみる。

$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

少し調べると、CentS6.5ではデフォルトで4.4.7が入るようになっている(古いまま更新されていない)らしい。
以下のサイトを参照しながら4.8を導入する

CentOS 6.5にGCC 4.8.2をレポジトリで入れてみた -- 以下省略!

まずはそれぞれのレポジトリからインストールを行う

# wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
# yum install devtoolset-2-gcc devtoolset-2-binutils
# yum install devtoolset-2-gcc-c++ devtoolset-2-gcc-gfortran

インストール後、バージョンを確認してみるとこうなっている。

$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ /opt/rh/devtoolset-2/root/usr/bin/gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

このままではgccが古いバージョンを参照したままのため、同時に導入されるらしいsclというコマンドを利用すると、gccのパスをいい感じに合わせてくれる。
sudoまたはrootで実行してしまうと、rootの使用gccのみが書き換わり、vagrantユーザーでnpm installしたときの参照gccは結局古いままになってしまうため注意。(一度引っかかった)

$ scl enable devtoolset-2 bash
$ gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

そうしてからもう一度npm installを行う

$ npm install mediasoup --no-bin-links

正常に通るのを確認して終了。お疲れ様でした。

2017/12/26 追記

gcc4.8の件は、shellを再起動するともとにもどるので、下記を~/.bashrcもしくは~/.bash_profilesに記載すべし

source /opt/rh/devtoolset-2/enable

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
6