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:
- npm install -g node-gyp nw-gyp node-pre-gyp
- npm install serialport
- cd into serialport module folder
- 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:
- npm install nw
- Pull nw out of node_modules
- Zip up everything BUT .git, node_modules, nw to app-name.zip
- Rename app-name.zip to app-name.nw
- Move the app-name.zip to nw/nwjs
- In standard windows command prompt (not a CYGWIN environment!) use the command copy /b nw.exe+app-name.nw app-name.exe
- Using Enigma Virtual Box set Input File Name to your app-name.exe file.
- Under Files, add the following:
- d3compiler_47.dll
- ffmpegsumo.dll
- icudtl.dat
- libEGL.dll
- libGLESv2.dll
- nw.pak
- 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.
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.