These instruction are for Windows, on my Linux installation(Fedora 21) everything works by just installing serialport with npm (I don't know why!).
These are the steps I did to build node serialport for electron (formerly atom-shell) for Windows. I am completely certain there is a better way to do it, but since I struggled with it for quite a while, here is a solution anyway.
You need some version of Visual studio installed, I have VS 2012 Express for Desktop.
There were a couple of issues that prevented a working build:
- node-pre-gyp and passing disturl to npm for customized headers
- electron version (or rather V8 version in electron)
- Using node-gyp when build depends on node-pre-gyp
Not needed for electron per se, but npm and maybe other tools needed is bundled with io.js
I used 1.8.1, 32 bit arch
Note: I used electron 0.24.0, since never versions came with v8 newer than used in latest io.js, which gave me toolchain mismatch when building. (I don't remember exact error, but something about NAN, serialport_win.cpp, V8 and 4 arguments in function signature)
Again I used 32 bit arch, I guess matching with same io.js arch results in minimum grievance.
Commands executed in io.js command shell
cd **your electron installation**/resources/default_app
npm install serialport
This results in succesful build, but against wrong headers, which gives Uncaught Error: Module did not self-register
.
This command fails, but it's ok since I just used this command to download correct headers. There is surely a better way to download them though.
cd node_modules/serialport
node-gyp rebuild --target=0.24.0 --dist-url=https://atom.io/download/atom-shell
Note: This fails with Undefined variable module_name in binding.gyp while trying to load binding
.
Note: just installing directly with correct headers (i.e. passing dist-url and target to npm) does not work.
This adds node-pre-gyp to the mix, and node-pre-gyp doesn't know what to do with Electrons versioning scheme.
Results in: node-pre-gyp ERR! stack Error: Unsupported target version
Move/rename/copy electron-headers(0.24.0) to 1.8.1 (io.js version)
cd **your home directory**/.node-gyp
mv 1.8.1 iojs_headers
mv 0.24.0 1.8.1
cd 1.8.1
mv ia32/node.lib ia32/iojs.lib
mv x64/node.lib x64/iojs.lib
Note I'm just guessing here, I really have no knowledge about node/iojs/electron libraries and headers.
This time this will build correct version, since headers are correct
cd **your electron installation**/resources/default_app
npm install serialport
Again, this works for me, your mileage may vary
Hi.. I did normal install but get:
App threw an error when running Error: Error en una rutina de inicialización de biblioteca de vínculos dinámicos (DLL).
?\C:\Program Files\nodejs\app\node_modules\serialport\build\Release\serialport.node
at Error (native)
at process.module.(anonymous function) as dlopen
at Object.Module._extensions..node (module.js:568:18)
at Object.module.(anonymous function) as .node
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at bindings (C:\Program Files\nodejs\app\node_modules\serialport\node_modules\bindings\bindings.js:76:44)
Any idea?