Npm install blickstick error

I’m trying to install blickstick for node.js on Windows 8.1 x64 and I’m getting this message:

C:\>npm install blinkstick
npm WARN optional dep failed, continuing usb-shyp-win32-ia32@0.3.x
npm WARN optional dep failed, continuing usb-shyp-win32-x64@0.3.x
npm WARN optional dep failed, continuing usb-shyp-darwin-x64@0.3.4

> usb@0.3.11 install C:\node_modules\blinkstick\node_modules\usb
> node shyp-blacklist.js win32-x64 win32-ia32 darwin-x64 || node-gyp rebuild


C:\node_modules\blinkstick\node_modules\usb>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
child_process: customFds option is deprecated, use stdio instead.
Warning: Missing input files:
C:\Program Files\libusb\MS64\dll\libusb-1.0.dll
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  Copying C:/Program Files/libusb/MS64/dll/libusb-1.0.dll to C:\node_modules\blinkstick\node_modules\usb\build\Release\\libusb-1.0.dll
  The system cannot find the path specified.
  node_usb.cc
  device.cc
  transfer.cc
c:\node_modules\blinkstick\node_modules\usb\src\node_usb.h(11): fatal error C1083: Cannot open include file: 'libusb.h': No such file or directory (..\src\device.cc) [C:\node_modules\blinkstick\node_modules\usb\build\usb_bindings.vcxproj]
c:\node_modules\blinkstick\node_modules\usb\src\node_usb.h(11): fatal error C1083: Cannot open include file: 'libusb.h': No such file or directory (..\src\transfer.cc) [C:\node_modules\blinkstick\node_modules\usb\build\usb_bindings.vcxproj]
c:\node_modules\blinkstick\node_modules\usb\src\node_usb.h(11): fatal error C1083: Cannot open include file: 'libusb.h': No such file or directory (..\src\node_usb.cc) [C:\node_modules\blinkstick\node_modules\usb\build\usb_bindings.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\node_modules\blinkstick\node_modules\usb
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "blinkstick"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! usb@0.3.11 install: `node shyp-blacklist.js win32-x64 win32-ia32 darwin-x64 || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the usb@0.3.11 install script 'node shyp-blacklist.js win32-x64 win32-ia32 darwin-x64 || node-gyp rebuild'.
npm ERR! This is most likely a problem with the usb package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node shyp-blacklist.js win32-x64 win32-ia32 darwin-x64 || node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls usb
npm ERR! There is likely additional logging output above.
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "blinkstick"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1

npm ERR! Uncaught, unspecified "error" event.
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     C:\npm-debug.log

Note that some of the paths mentioned in the error message (C:\node_modules…) make no sense.

Please help me install blinkstick.

Suspecting that this is an issue with Windows 8. Working on this. Will let you know tomorrow.

It seems that this may be because blinkstick does not work with Node v0.12?
Also I noticed the usb module used by blinkstick is an older version, not sure if that’s a problem though.

I’ve got it working on Node v0.10 using a stand-alone blinkstick (not the npm install one).

Thanks for this. I managed to reproduce it, but my development system was behind and on Node 0.10.26. I’ll update to the latest and apply the required fixes to support Node 0.12.

Sorry about the inconvenience, will let you know when it’s done.

This should now be sorted. I’ve pushed a new BlinkStick Node.js module release to address this issue. Thanks for reporting!

Alas: I can now install it, but not run it.

H:\dev\node\test>node -v
v0.12.0

H:\dev\node\test>npm -v
2.5.1

H:\dev\node\test>npm install blinkstick
npm WARN optional dep failed, continuing usb-shyp-darwin-x64@1.0.4

> usb@1.0.4 install H:\dev\node\test\node_modules\blinkstick\node_modules\usb
> node shyp-blacklist.js win32-x64 win32-ia32 darwin-x64 || node-gyp rebuild

blinkstick@1.1.1 node_modules\blinkstick
+-- usb@1.0.4 (bindings-shyp@0.2.3, nan@1.6.2, usb-shyp-win32-ia32@1.0.4, usb-shyp-win32-x64@1.0.4)

H:\dev\node\test>type test.js
require('blinkstick')

H:\dev\node\test>node test.js
module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: The specified procedure could not be found.
H:\dev\node\test\node_modules\blinkstick\platform\windows\HID.node
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (H:\dev\node\test\node_modules\blinkstick\blinkstick.js:11:11)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

H:\dev\node\test>

Also, that was using the x86 version of nodejs. Using the x64 version, the HID.node will not load at all, as it is compiled for x86.

H:\dev\node\test>node test.js
module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: %1 is not a valid Win32 application.
H:\dev\node\test\node_modules\blinkstick\platform\windows\HID.node
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (H:\dev\node\test\node_modules\blinkstick\blinkstick.js:11:11)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

H:\dev\node\test>

Not sure if I’ll be able to support 64 bit version of Node.js. Booting a VM with Windows 8 to check if I can reproduce your issue.

I can confirm that there is an issue with the precompiled HID module on Windows 8. Looking for a way to fix this.

Is HID.node a build of node-hid? If so, did you make any changes to it to get it to work with blinkstick?

I’d like to know so I can have a go at compiling HID.node myself. I think I make it work on both x86 and x64 by compiling two versions of HID.node and having the script decide which one to load, or having it attempt to load both and use whichever works - I’m doning a similar thing for an addon I’m working on.

Seems that I may not be able to support 64 bit version of Node.js, but I think I have a fix for 32 bit version. I haven’t released to npm yet and it’s only available in the repository. Would you be able to test this for me if it works on your system please? Here are the steps:

  • Download zip package
  • Create folder H:\dev\node\test\node_modules
  • Extract the contents of the archive to H:\dev\node\test\node_modules\blinkstick so that you have H:\dev\node\test\node_modules\blinkstick\package.json and etc
  • There should be no need to run npm install inside the folder
  • Open cmd.exe
  • cd H:\dev\node\test\node_modules\blinkstick
  • node examples\blink\blink.js

Please let me know if it works for you and BlinkStick starts blinking.

Yes, it works on v0.12 x86 now, thank you!

Great! Thanks for testing this. I’ll release a new version of package tomorrow after I complete the tests with earlier versions of Node.js. For now please use the version from Github and I’ll notify about the new release.

Thanks, will do.

I just compiled my own addon for x86 and x64 on v0.10 and v0.12. I’ve thus created four version of the .node file and put them in a tree such that I have ia32/0.10/name.node, ia32/0.12/name.node, x64/0.10/name.node, and x64/0.12/name.node. Then I use an index.js to load the correct binary like so:

var sArchitecture = process.arch;
var sVersion = process.versions.node.match(/^(\d+\.\d+)\.\d+$/)[1];
module.exports = require("./bin/" + sArchitecture + "/" + sVersion + "/" + sModuleName);

I’m assuming HID.node is a build of node-hid? I ask because I can build that for v0.10 x64 myself. However, I can’t build it for v0.12 at all - they don’t seem to use Nan. You appear to have “patched” yours, care to share how you got it working?

This is actually an ideal solution to load all required version of HID module. I want to provide precompiled HID modules for BlinkStick package, because it’s such a pain to set up a build environment on Windows in order to use gyp based installation for node-hid. It’s not the case on Linux or OSX.

It is in fact node-hid which I have forked. My patches have been applied from another repository which claims to be incomplete, but seem to be working on my platform. However I didn’t manage to build them for the 64bit version of Node.js on Windows with the patches applied. Might be something missing and I would need to investigate this further. The forked repository and applied patches are on develop branch available here:

The breaking changes in Node.js API occurred in 0.11.13. You can see this check in my code to cover the case. However I would be very interested to cover all platforms and versions of Node.js like you did. Currently my solution only covers x86.

I’ve successfully implemented the “multi-.node loader” that I used with my own addon in both your node-hid and blinkstick code. I’ve sent pull requests for both for your consideration.

NB. This is my first time working with github, so I am not sure I did everything correctly.

PS. I had no problem building your original node-hid for x64, so I’d be interested to hear what errors you were seeing. Might it be related to your build environment, rather than the code?

Thanks for the pull request, I’ll review and come back to you. One thing that concerns me straight away is that this only works with 0.10-0.13 version of Node.js. When 0.14 is release we would be forced to recreate the files otherwise the package wouldn’t work which may not be necessary. Also I need to look if I have to support node versions 0.8 and 0.9.

You are right. I will create a fall-back mechanism where a previous version is automatically selected if the desired version is not available. I will do another pull when it’s ready.

It seems I do not have to create a new pull request, but my previous one is automatically updated to include the changes I suggested.

I’ve updated the code to attempt to load all available versions of the “.node” file for the user’s processor architecture. The first one to successfully load will be used. This has the added benefit of allowing me to remove the 0.12 version of the code as the 0.11 version works just fine in 0.12. It also means that unless there are new changes to the addon format, you do not need to build any new “.node” files for future version of node.js.

You can test if the 0.10 version works in 0.8 and 0.9, if it does not, you can simply add 0.8 to the list in build-targets.txt and run install.cmd to create additional “.node” files. Then test if they work in 0.9 and if not, add that to the list too, etc.
EDIT: I’ve tested it and the 0.10 version will not work in 0.8 or 0.9, so I added 0.8.9 and 0.9.9 to the build-targets.txt file. I was unable to build the 0.9.9 version because of an error:

HID.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class v8::Handle<class v8::Value> __cdecl node::MakeCallback(class v8::Handle<class v8::Object>,class v8::Handle<class v8::Function>,int,class v8::Handle<class v8::Value> * const)" (__imp_?MakeCallback@node@@YA?AV?$Handle@VValue@v8@@@v8@@V?$Handle@VObject@v8@@@3@V?$Handle@VFunction@v8@@@3@HQAV23@@Z) [H:\dev\node\node-hid\build\HID.vcxproj]
H:\dev\node\node-hid\build\Release\HID.node : fatal error LNK1120: 1 unresolved externals [H:\dev\node\node-hid\build\HID.vcxproj]

Update: I was able to build for 0.9.7, but it appears that module will not load in 0.9.8 or 0.9.9.
It starting to look like supporting all versions of node with pre-compiled binaries may be a stretch goal, but using multiple versions should definitely be an improvement from the original.

PS. To make testing different version of node.js easier, I have done a similar thing with “node.exe” files: I’ve downloaded standalone node.exe executables and saved them in a folder structure. I’ve also created a #node.cmd file which will run any script in a given version of node

+ #node.cmd
+ node/
  + ia32/
      + 0.10.36/
          + node.exe
      + 0.11.16/
          + node.exe
      + 0.12.0/
          + node.exe
  + x64/
      + 0.10.36/
          + node.exe
      + 0.11.16/
          + node.exe
      + 0.12.0/
          + node.exe

Usage:

    #node.cmd [arch] [version] [script] [arguments]

Example:

    #node.cmd ia32 0.10 node-hid.js

Source:

@ECHO OFF

FOR /F "usebackq" %%I IN (`dir /B "%~dp0node\%~1\%~2.*" 2^>nul ^| sort /R`) DO (
  CALL :FOUND "%~dp0node\%~1\%%~I\node.exe" %*
  EXIT /B 0
)
ECHO The requested version of node was not found.
EXIT /B 1

:FOUND
  SET COMMAND=%1
  SHIFT
  SHIFT
  :ADD_ARGUMENTS
    SHIFT
    if "%~1" == "" (
      %COMMAND%
      EXIT /B %ERRORLEVEL%
    )
    SET COMMAND=%COMMAND% %1
    GOTO ADD_ARGUMENTS

I hope this helps.