带有USB模块的Node webkit应用程序失败

Node webkit application with USB module failing

本文关键字:webkit 应用程序 失败 Node USB 模块 带有      更新时间:2023-09-26

我正在使用node-webkit编写一个桌面应用程序。我使用节点USB模块编写脚本,如果我使用节点运行该脚本,则该模块工作正常。它列出了所有usb设备,连接,读取,写入。现在我想实现相同的使用node-webkit应用程序,其中HTML有一个按钮,我们必须做这些事情。现在,我们需要配置节点模块。我已经将该模块添加到我的项目中,然后做了如上所述的处理

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');   });})();

使用nw

运行应用程序时出现以下错误<>之前"%1不是有效的Win32应用程序。↵D: ' '项目……呃' node_modules ' u盘' src '绑定' usb_bindings.node"}之前有谁能帮我一下吗?

我通过编译正确的体系结构解决了这个问题。在我的环境中,node是32位,而nw是64位。将目录更改为usb模块,下面两个命令通过创建64位版本的本机绑定解决了这个问题:

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

module_namemodule_path变量是必要的,因为无论出于何种原因,nw-gyp没有从binding.gyp文件中获得它们的值。

另一个可能导致您描述的错误的事情是将nw.exe重命名为其他东西。只要命名为nw.exe,符号就会正确绑定。