Windows7 に Node.js の bcrypt を入れるメモ

Node.js に bcrypt を入れようとしたら「OpenSSLもねーくせに調子のるな」みたいなエラーメッセージが吐き出されたので頑張ってインストールしたメモです。

エラーメッセージはこんな感じ

npm http GET https://registry.npmjs.org/bcrypt
npm http 304 https://registry.npmjs.org/bcrypt
npm http GET https://registry.npmjs.org/bindings/1.0.0
npm http 304 https://registry.npmjs.org/bindings/1.0.0

> bcrypt@0.7.6 install C:\Users\fumito.ito\js_projects\LEDITA\node_modules\bcrypt
> node-gyp rebuild


C:\Users\fumito.ito\js_projects\LEDITA\node_modules\bcrypt>node "C:\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js
" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  blowfish.cc
  bcrypt.cc
  bcrypt_node.cc
..\src\bcrypt.cc(232): warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data [C:\Users\fumito.ito\js_projects\LEDITA\n
ode_modules\bcrypt\build\bcrypt_lib.vcxproj]
C:\app\MicrosoftVisualStudio11.0\VC\include\xlocale(336): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /E
Hsc (..\src\bcrypt_node.cc) [C:\Users\fumito.ito\js_projects\LEDITA\node_modules\bcrypt\build\bcrypt_lib.vcxproj]
..\src\bcrypt_node.cc(38): fatal error C1083: Cannot open include file: 'openssl/rand.h': No such file or directory [C:\Users\fumito.ito\js_projects\LED
ITA\node_modules\bcrypt\build\bcrypt_lib.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\fumito.ito\js_projects\LEDITA\node_modules\bcrypt
gyp ERR! node -v v0.10.7
gyp ERR! node-gyp -v v0.9.5
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

インストールの前準備

以下のモジュールが必要です。

  • python 2.7
  • Microsoft Visual Studio C++ 2010
  • node-gyp
  • OpenSSL (Win32OpenSSL-1_0_1c.exe or Win64OpenSSL-1_0_1c.exe)

ちなみに自機がWindows 7 x64 なのでOpenSSLは64bit版を使っています。
Node.jsのバージョンは0.10.15でした。

python 2.7

インストーラー

Microsoft Visual Studio C++ 2010

このへん に詳しく書いてあります。

node-gyp

npm install -g node-gyp

OpenSSL

インストーラー

インストール後に OpenSSL-Win64\bin にPathを通しておきましょう。 ちなみにですが、 light がついているやつでは ダメ です。これでしばらくハマりました。

インストール

普通に npm install bcrypt するだけで入ります。
ほかのモジュールに突っ込むときなどはちょっと不安なので bcrypt 本体を落としてきてビルドできるかどうか確かめてみるのが無難でしょう。
ぐたいてきにはこんな感じ になります。