Windows7 64bitでnode-serialportのインストールが出来なかったがWindows8.1ではうまくいった話

Arduinoとシリアルポートの連携をしたいがために、node-serialportを使いたくてWindows7 64bitのPCに入れようと頑張ったものの結局できなくて、Windows8.1ではあっさりうまくいったメモです。

まずWindows7ではうまく行かなかった・・・。

こちらにあるように、

voodootikigod/node-serialport

Windows:

Windows 7 or Windows 8.1 are supported.
* Install Visual Studio Express 2013 for Windows Desktop.
* If you are hacking on an Arduino, be sure to install the drivers.
* Install node.js 0.10.x matching the bitness (32 or 64) of your operating system.
* Install Python 2.7.6 matching the bitness of your operating system. For any questions, please refer to their FAQ. Default settings are perfect.
* Open the 'Visual Studio Command Prompt' and add Python to the path.

に従って、

  • Visual Studio Express 2013 for Windows Desktopをインストール
  • Python2.7.xを入れてPATH変数を通す
  • Arduinoのインストール済みであればドライバは入っているはず
  • node-pre-gypをnpmインストール
  • node-gypをnpmインストール

といったところまで進めても、以下エラーから抜けだせなかった。

**************************>npm install serialport
npm http GET https://registry.npmjs.org/serialport
npm http 304 https://registry.npmjs.org/serialport
npm http GET https://registry.npmjs.org/async/0.9.0
npm http GET https://registry.npmjs.org/bindings/1.2.1
npm http GET https://registry.npmjs.org/nan/1.7.0
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/sf/0.1.7
npm http 304 https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/nan/1.7.0
npm http 304 https://registry.npmjs.org/sf/0.1.7
npm http 304 https://registry.npmjs.org/bindings/1.2.1
npm http 304 https://registry.npmjs.org/async/0.9.0
npm http GET https://registry.npmjs.org/ms/0.7.0
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/minimist
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/minimist
npm http 304 https://registry.npmjs.org/ms/0.7.0

    serialport@1.6.3 install **************************\node_modul
es\serialport
    node-pre-gyp install --fallback-to-build

node-pre-gyp http GET https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz
node-pre-gyp http 404 https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz
node-pre-gyp http Pre-built binary not available for your system (falling back to source compile with node-gyp)

**************************\node_modules\serialport>node "C:\Prog
ram Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild --name=serialport --configuration=Release --module_name=serialport --version=1.6.3 --major=1 --minor=6 --patch=3 --runtime=node --node_abi=node-v11 --platform=win32 --target_platform=win32 --arch=x64 --target_arch=x64 --module_main=./serialport --host=https://node-serialport.s3.amazonaws.com/ --module_path=**************************\node_modules\serialport\build\serialport\v1.6.3\Release\node-v11-win32-x64 --remote_path=./serialport/v1.6.3/Release/ --package_name=node-v11-win32-x64.tar.gz --staged_tarball=build\stage\serialport\v1.6.3\Release\node-v11-win32-x64.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz
gyp ERR! configure error
gyp ERR! stack Error: spawn ENOENT
gyp ERR! stack     at errnoException (child_process.js:980:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:771:34)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--name=serialport" "--configuration=Release" "--module_name=serialport" "--version=1.6.3" "--major=1" "--minor=6" "--patch=3" "--runtime=node" "--node_abi=node-v11" "--platform=win32" "--target_platform=win32" "--arch=x64" "--target_arch=x64" "--module_main=./serialport" "--host=https://node-serialport.s3.amazonaws.com/" "--module_path=F:\\Creative\\git\\heroku\\demo-1ft-nodeserial\\node_modules\\serialport\\build\\serialport\\v1.6.3\\Release\\node-v11-win32-x64" "--remote_path=./serialport/v1.6.3/Release/" "--package_name=node-v11-win32-x64.tar.gz" "--staged_tarball=build\\stage\\serialport\\v1.6.3\\Release\\node-v11-win32-x64.tar.gz" "--hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/" "--hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz"
gyp ERR! cwd **************************\node_modules\serialport
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp.cmd rebuild --name=serialport --configuration=Release --module_name=serialport --version=1.6.3 --major=1 --minor=6 --patch=3 --runtime=node --node_abi=node-v11 --platform=win32 --target_platform=win32 --arch=x64 --target_arch=x64 --module_main=./serialport --host=https://node-serialport.s3.amazonaws.com/ --module_path=F:\Creative\git\heroku\demo-1ft-nodeserial\node_modules\serialport\build\serialport\v1.6.3\Release\node-v11-win32-x64 --remote_path=./serialport/v1.6.3/Release/ --package_name=node-v11-win32-x64.tar.gz --staged_tarball=build\stage\serialport\v1.6.3\Release\node-v11-win32-x64.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous    (**************************\node_modules\serialport\node_modules\node-pre-gyp\lib\util\c
ompile.js:76:29)
node-pre-gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
node-pre-gyp ERR! stack     at maybeClose (child_process.js:735:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:802:5)
node-pre-gyp ERR! System Windows_NT 6.1.7601
node-pre-gyp ERR! command "node" "**************************\\node_modules\\serialport\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "inst
all" "--fallback-to-build"
node-pre-gyp ERR! cwd **************************\node_modules\se
rialport
node-pre-gyp ERR! node -v v0.10.22
node-pre-gyp ERR! node-pre-gyp -v v0.5.19
node-pre-gyp ERR! not ok
Failed to execute 'node-gyp.cmd rebuild --name=serialport --configuration=Release --module_name=serialport --version=1.6.3 --major=1 --minor=6 --patch=3 --runtime=node --node_abi=node-v11 --platform=win32 --target_platform=win32 --arch=x64--target_arch=x64 --module_main=./serialport --host=https://node-serialport.s3.amazonaws.com/ --module_path=**************************\node_modules\serialport\build\serialport\v1.6.3\Release\node-v11-win32-x64 --remote_path=./serialport/v1.6.3/Release/ --package_name=node-v11-win32-x64.tar.gz --staged_tarball=build\stage\serialport\v1.6.3\Release\node-v11-win32-x64.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz' (1)
npm ERR! serialport@1.6.3 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the serialport@1.6.3 install script.
npm ERR! This is most likely a problem with the serialport package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR!     npm owner ls serialport
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "serialport"
npm ERR! cwd **************************
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     **************************\npm-debug.log
npm ERR! not ok code 0

**************************>node node-pre-gyp rebuild --runtime=node-webkit --target=0.9.2

module.js:340
    throw err;
          ^
Error: Cannot find module '**************************'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

エラーコードを元に調べてみたものの、どうも解決策が見えてこない。途中、インストールとアンインストールを繰り返したので、なにか壊してしまっているかもしれない。

Windows8.1で入れてみたらうまくいった

ネットの文献を見ているとどうもMacかWindows8.1でうまくいっているケースが多いようで、あまり気が進まないがWindows8.1のノートPCに入れてみたところうまくいきました。

Python2.7.xをインストール

Welcome to Python.org

image_20150403_002915_1

下のダウンロードからPython2.7のリンクをクリック。

image_20150403_002915_2

ダウンロードページで

image_20150403_002915_3

64bitのインストーラーをダウンロードしてインストール。

image_20150403_002915_4

Windows x86-x64 MSI Installerという名前のですね。

image_20150403_002915_5

続いて、Visual Studioをインストール

ダウンロードページに行きます。

Visual Studioダウンロード

image_20150403_002915_6

Express 2013 with Update 4 for Windows Desktop をインストール。

image_20150403_002915_7

image_20150403_002915_8

Pythonのパスを通す

コマンドラインでPythonが使えるようにパスを通します。

image_20150403_003641_5

C:\Python27 にインストールした場合、PATHにC:\Python27を追加します。

node-gypとnode-pre-gypをグローバルに入れておく

Node.js – Windows8でnode-gypを入れるメモ – Qiita

こちらにあるように、node-gypとnode-pre-gypを入れておきます。

npm install node-gyp -g
npm install node-pre-gyp -g

インストールしたいフォルダに移動してnode-serialportをインストール

いよいよnode-serialportインストールです。インストールしたいフォルダに移動します。

npm install serialport

と、打ちます。以下のように、ダーッとログが出てビルドが成功します。

serialport@1.6.3 install C:\Creative\Data\git\sample\node_modules\serialport
node-pre-gyp install --fallback-to-build


C:\Creative\Data\git\sample\node_modules\serialport>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild --name=serialport --configuration=Release --module_name=serialport --version=1.6.3 --major=1 --minor=6 --patch=3 --runtime=node --node_abi=node-v11 --platform=win32 --target_platform=win32 --arch=x64 --target_arch=x64 --module_main=./serialport --host=https://node-serialport.s3.amazonaws.com/ --module_path=C:\Creative\Data\git\sample\node_modules\serialport\build\serialport\v1.6.3\Release\node-v11-win32-x64 --remote_path=./serialport/v1.6.3/Release/ --package_name=node-v11-win32-x64.tar.gz --staged_tarball=build\stage\serialport\v1.6.3\Release\node-v11-win32-x64.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.6.3/Release/node-v11-win32-x64.tar.gz 
このソリューション内のプロジェクトを 1 度に 1 つずつビルドします。並行ビルドを有効にするには、"/m" スイッチを追加してください。
  serialport.cpp
  serialport_win.cpp
  enumser.cpp

(略)

     ライブラリ C:\Creative\Data\git\sample\node_modules\serialport\build\Release\serialport.lib とオブジェクト C:\Creative\Data\git\sample\node_modules\serialport\build\Release\serialport.exp を作成中
  コード生成しています。
  コード生成が終了しました。
  serialport.vcxproj -> C:\Creative\Data\git\sample\node_modules\serialport\build\Release\\serialport.node
  Copying C:\Creative\Data\git\sample\node_modules\serialport\build\Release\/serialport.node to C:/Creative/Data/git/sample/node_modules/serialport/build/serialport/v1.6.3/Release/node-v11-win32-x64\serialport.node
          1 個のファイルをコピーしました。
serialport@1.6.3 node_modules\serialport
bindings@1.2.1
sf@0.1.7
async@0.9.0
nan@1.7.0
debug@2.1.3 (ms@0.7.0)
optimist@0.6.1 (wordwrap@0.0.2, minimist@0.0.10)

バージョン確認

無事インストールされたので、バージョンを確認します。

npm serialport --version

と、打つと

1.4.14

と出てインストール完了です。

おわりに

いかがでしたでしょうか。Windows7 64bitでインストールできなかったのには焦りましたが、Windows8.1でうまくいって一安心です。

Windows7 64bitはどうもビルド前後でコケているようなんですが、また色々見えてきたらトライしてみようと思います。

それでは、よきNodeJS & serialport Lifeを。