building serialport.js with nw.gyp for nw.js

2019-09-04 15:26发布

问题:

I'm trying to package serialport.js with my nw.js app. I'm having a hard time building serialport.js for nw.js.

I've installed serialport.js in my "app\resource\node_modules" using npm.

I've also installed nw.gyp globally "npm install nw-gyp -g"

Then I changed directory to "app\resource\node_modules\serialport" where the binding.gyp is located and tried to rebuild serialport with nw-gyp "nw-gyp rebuild --target=0.12.3"

This is the error I got: Undefined variable module_name in binding.gyp

Any Ideas how I can get passed this problem?

Other's seem to have similar problems: Serialport.js in Node-webkit (nw.js) on Win 7

I also saw the same error happening with a different node module: Building node-sqlite3 with nw-gyp

回答1:

open node_modules/serialport/binding.gyp, you need make some changes...

before:

  "target_name": "action_after_build",
  "type": "none",
  "dependencies": [ "<(module_name)" ],
  "copies": [
    {
      "files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
      "destination": "<(module_path)"

after:

  "target_name": "action_after_build",
  "type": "none",
  "dependencies": [ "serialport" ],
  "copies": [
    {
      "files": [ "<(PRODUCT_DIR)/serialport.node" ],
      "destination": "."

And change module_path in node_modules/serialport/package.json for:

"module_path": "./build/{configuration}/",

Finally, run nw-gyp rebuild --target=0.12.3