0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Raspbianでのnpm install leveldownではまったメモ

Last updated at Posted at 2017-04-12

で、Web of Things frameworkをRaspberry pi3で動かそうとしてインストール時に
leveldownというモジュールのビルドエラーではまったときのメモ。

環境

結論

nodeのバージョン問題。

プリインされてるnode -v 0.10.29 ではダメ。
node -v 6.10.2 にしてみたら解決した。

経緯

npm install leveldownのインストール中、下記エラーでコケた。

  CXX(target) Release/obj.target/leveldown/src/batch.o
In file included from ../src/batch.cc:3:0:
../node_modules/nan/nan.h:324:47: error: ?REPLACE_INVALID_UTF8? is not a member of ?v8::String?
   static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
                                               ^
leveldown.target.mk:99: recipe for target 'Release/obj.target/leveldown/src/batch.o' failed
make: *** [Release/obj.target/leveldown/src/batch.o] Error 1
make: Leaving directory '/home/pi/web-of-things-framework/node_modules/leveldown/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:809:12)
gyp ERR! System Linux 4.4.50-v7+
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/pi/web-of-things-framework/node_modules/leveldown
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! leveldown@1.6.0 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the leveldown@1.6.0 install script.
npm ERR! This is most likely a problem with the leveldown package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     prebuild-install || node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls leveldown
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 4.4.50-v7+
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "leveldown"
npm ERR! cwd /home/pi/web-of-things-framework
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/pi/web-of-things-framework/npm-debug.log
npm ERR! not ok code 0

In file included from ../src/batch.cc:3:0:
../node_modules/nan/nan.h:324:47: error: ?REPLACE_INVALID_UTF8? is not a member of ?v8::String?
   static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;

とのことなので、ソースを見てみると
nan.hには

316 namespace imp {
317   static const size_t kMaxLength = 0x3fffffff;
318   // v8::String::REPLACE_INVALID_UTF8 was introduced
319   // in node.js v0.10.29 and v0.8.27.
320 #if NODE_MAJOR_VERSION > 0 || \
321     NODE_MINOR_VERSION > 10 || \
322     NODE_MINOR_VERSION == 10 && NODE_PATCH_VERSION >= 29 || \
323     NODE_MINOR_VERSION == 8 && NODE_PATCH_VERSION >= 27
324   static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
325 #else
326   static const unsigned kReplaceInvalidUtf8 = 0;
327 #endif
328 }  // end of namespace imp

コメントによると、問題のv8::String::REPLACE_INVALID_UTF8はnode.js v0.10.29 and v0.8.27から導入されたとのこと。

だが現在使っているのは
node -v v0.10.29
npm -v 1.4.21
なので、問題ないはずだが?

と思って調べた結果

0.10.29でちゃんと入っている。

じゃあラズパイに入っているnodeのヘッダがおかしい?
v8.hを探したら

/usr/include/v8.h
/usr/include/nodejs/deps/v8/include/v8.h

にあって、どちらにもREPLACE_INVALID_UTF8がやはり入ってない。
どういうことか?

もうよくわからないのでnvm入れて新たにnode.jsを入れ直すことにする。
とりあえず試しに同じversionの0.10.29をインストール。
完了後、~/.nvm/v0.10.29/include/node/v8.hを見ると、ちゃんとREPLACE_INVALID_UTF8が入ったものになっている。
それでこの問題は無事解決。


しかし今度は別のエラーが。。

  CXX(target) Release/obj.target/leveldown/src/iterator.o
In file included from /home/pi/.node-gyp/0.10.29/src/node.h:62:0,
                 from ../src/iterator.cc:6:
/home/pi/.node-gyp/0.10.29/deps/v8/include/v8.h: In instantiation of ‘static v8::Local<T> v8::Local<T>::Cast(v8::Local<S>) [with S                                                                             = v8::Value; T = v8::Value]’:
/home/pi/.node-gyp/0.10.29/deps/v8/include/v8.h:292:32:   required from ‘v8::Local<S> v8::Local<T>::As() [with S = v8::Value; T = v                                                                            8::Value]’
../src/iterator.cc:273:61:   required from here
/home/pi/.node-gyp/0.10.29/deps/v8/include/v8.h:288:34: error: ‘Cast’ is not a member of ‘v8::Value’
     return Local<T>(T::Cast(*that));
                                  ^
/home/pi/.node-gyp/0.10.29/deps/v8/include/v8.h: In static member function ‘static v8::Local<T> v8::Local<T>::Cast(v8::Local<S>) [w                                                                            ith S = v8::Value; T = v8::Value]’:
/home/pi/.node-gyp/0.10.29/deps/v8/include/v8.h:289:3: warning: control reaches end of non-void function [-Wreturn-type]
   }
   ^
leveldown.target.mk:99: recipe for target 'Release/obj.target/leveldown/src/iterator.o' failed

そもそも、nodeのバージョンの問題ではないだろうかということで、
nvm install v6.10.2

問題解決。。

0
2
0

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
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?