Skip to content

Instantly share code, notes, and snippets.

@hlfshell
Last active August 29, 2015 14:25
Show Gist options
  • Save hlfshell/3526882d232f7eee214e to your computer and use it in GitHub Desktop.
Save hlfshell/3526882d232f7eee214e to your computer and use it in GitHub Desktop.
How to build node-serialport on windows for an NW app.

Recently, I succeeded in building node-serialport for a windows NW app. This proved quite problematic, and I have decided to write down necessary steps to get it to run.

First, I would like to point out an excellent article written by the writer/maintainer of node-serialport highlighting why it is extremely difficult to keep node-serialport compatible with all the different node runtimes. Read it and appreciate the effort VoodooTikiGod puts in for us.

Before any action is taken, you need to install all pre-reqs for building with node-gyp native C/C++ modules. The most concise set of instructions that always works I've found is here.

The default build instructions for building native modules for an nw-app are here. The instructions I use, specifically, are:

  1. npm install -g node-gyp nw-gyp node-pre-gyp
  2. npm install serialport
  3. cd into serialport module folder
  4. node-pre-gyp rebuild --runtime=node-webkit --target=0.12.2

Note on step 3: The target version # will change around based on what version of NW.js you are using.

This should setup serialport to work for NW, including the final packaging.

Here's my packaging method:

  1. npm install nw
  2. Pull nw out of node_modules
  3. Zip up everything BUT .git, node_modules, nw to app-name.zip
  4. Rename app-name.zip to app-name.nw
  5. Move the app-name.zip to nw/nwjs
  6. In standard windows command prompt (not a CYGWIN environment!) use the command copy /b nw.exe+app-name.nw app-name.exe
  7. Using Enigma Virtual Box set Input File Name to your app-name.exe file.
  8. Under Files, add the following:
  • d3compiler_47.dll
  • ffmpegsumo.dll
  • icudtl.dat
  • libEGL.dll
  • libGLESv2.dll
  • nw.pak
  1. Move your packaged app, possibly rename it to nw.exe (see below).

Additional note: My app would work with npm start, but would not find the serial library once packaged with Enigma Virtual Box. The solution was quite weird - rename the executable to be nw.exe and the error disappeared.

Building serialport when it's a sub-module

When building serialport when it's a sub-module (such as in my serial-rfid-reader module), I have ran into several problems resulting in the application building but, upon launch, it running the default NW.js hello world. It seems moving the built module to your main node_modules will solve.

Example:

If you use serial-rfid-reader, after npm install, move the node_modules/serail-rfid-reader/node_modules/serialport folder up to /node_modules, and then do the node-pre-gyp rebuild steps.

I do not know yet what to do if you require multiple versions of the same native C/C++ modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment