1

I am writing an desktop application using node-webkit. I have written script using Node USB module which is working fine if i run that script using node. It lists all usb devices , connects,reads,writes. Now I want to achieve same using node-webkit application where HTML has a button on which we have to do these things. Now for this we require to configure node modules. I have added that module to my project and then did process as mentioned

package.json:

{
  "name": "node-webkit-angular-bootstrap-starter",
  "version": "0.0.1",
  "description": "Starter destkop app using node-webkit, html5, angular, and bootstrap",
  "main": "app/index.html",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT",
  "window": {
    "title": "node-webkit-angular-bootstrap-starter",    
    "toolbar": true,
    "frame": true,
    "width": 1024,
    "height": 768,
    "position": "center"
  },
  "dependencies"  : {
    "node-pre-gyp": "0.6.9"
  },
  "bundledDependencies":["node-pre-gyp"],
  "devDependencies": {
    "aws-sdk": "~2.0.0-rc.15"
  },
  "scripts": {
    "install": "node-pre-gyp install --fallback-to-build"
  },
  "binary": {
    "module_name": "usb",
    "module_path": "./app/lib/binding/",
    "host": "https://github.com/camsoupa/node-usb"
  }
}

Home.js:

(function () {    'use strict';  app.controller('homeController', function ($scope) {alert("Heelooooo");


var gui = require('nw.gui');
var os = require('os'); 

$scope.settings = [];
$scope.usb = require('usb');   });})();

I am getting following error for running the application using nw

"%1 is not a valid Win32 application.
↵D:\Projects\…er\node_modules\usb\src\binding\usb_bindings.node"}

Can some one please help me?

Shraddha Shravagi
  • 1,096
  • 1
  • 9
  • 22
  • I have same issue. The usb module refuses to work, even after compiling with nw-gyp and the proper incantations for the correct nwjs version. – Centijo Feb 15 '16 at 18:01
  • please check my answer to this question it could help you: http://stackoverflow.com/a/39405308/427622 – Fareed Alnamrouti Sep 09 '16 at 10:06

1 Answers1

0

I solved this issue in my case by compiling for the correct architecture. In my environment, node is 32-bit while nw is 64-bit. Changing directories to the usb module, the following two commands resolved the issue by creating a 64-bit version of the native bindings:

nw-gyp configure --target=0.12.3 --module_name=usb_bindings --module_path=..\src\binding\ --target_arch=x64

nw-gyp build --target=0.12.3 --module_name=usb_bindings --module_path=..\src\binding\ --target_arch=x64

The module_name and module_path variables are necessary because for whatever reason, nw-gyp isn't getting their values from the binding.gyp file.

One more thing that can cause the error you described is renaming nw.exe to something else. As long as it is named nw.exe, the symbols will bind correctly.

Centijo
  • 584
  • 6
  • 15