serialport / node-serialport

Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
https://serialport.io
MIT License
5.82k stars 1.01k forks source link

Tracking Electron support #538

Closed a-giovani17 closed 7 years ago

a-giovani17 commented 9 years ago

I have an Electron desktop app that requires some nodejs packages including serialport. But only serialport is failed to require.

I included it like this:

var SerialPort = require('serialport').SerialPort; var sp = require('serialport');

But when I run it on Electron, it shows following error:

Error: Cannot find module 'C:\xampp\htdocs\simplemail-desktop\node_modules\serialport\build\serialport\v1.7.4\Release\node-v43-win32-ia32\serialport.node'

I've check that the folder actually doesn't exists. When I installed serialport, it created folder 'node-v14-win32-ia32' instead of 'node-v43-win32-ia32'. Maybe there is something wrong in the installation process. What should I do?

reconbot commented 8 years ago

Also if you all could test serialport@2.0.7-beta5 it's our release candidate. It's got a single change from beta4 around where the binaries go that should make your life a little easier when you rebuild.

techninja commented 8 years ago

@reconbot Just tried out Beta5, Default node install works.. a bit messier in the build/Release folder, but it works. What still does not work, is that since there's only one binary output folder, electron-rebuild will refuse to step on it. You must delete serialport.node before rebuild will take over, but rebuild does work beautifully (and quietly!) after that.

Unfortunately for my use case I need to be able to have both of these binaries (Node.js terminal and Electron) available as I allow users to run serialport in just Electron, or in both Electron and a Node.js child process. This worked just fine in previous releases as I could actually keep the binaries for all the OS' together, and would then be able to also keep the v46 node v4.x built bins right next to the v47s for the latest node5 in Electron. Truth is if they use the same binary, I have yet to see the actual fault, as long as they use the same module version.

rafaberaldo commented 8 years ago

@reconbot serialport@2.0.7-beta4 worked well for me with Electron 0.37.4, I just had to delete serialport.node.

Thank you.

reconbot commented 8 years ago

That's annoying, good to hear though. I'll open an issue with them if there isn't one already.

On Sat, Apr 9, 2016, 4:48 PM pimpaa notifications@github.com wrote:

@reconbot https://github.com/reconbot serialport@2.0.7-beta5 worked well for me with Electron 0.37.4, I just had to delete serialport.node.

Thank you.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/voodootikigod/node-serialport/issues/538#issuecomment-207852190

reconbot commented 8 years ago

Are there other binary packages that work without needing this extra step of removing the binary?

ajfisher commented 8 years ago

So I've just tried on my Mac plus an RPi, both running 5.10.x (using nvm) - straight install using serial port beta 5 plus electron latest plus Johnny five latest.

Worked fine on both platforms without an issue now it seems.

On Sun, Apr 10, 2016, 13:14 Francis Gulotta notifications@github.com wrote:

Are there other binary packages that work without needing this extra step of removing the binary?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/voodootikigod/node-serialport/issues/538#issuecomment-207904613

gohackfelipe commented 8 years ago

Hi guys! Please... someone help me!

Using electron and serialport

When I run:

Error: Uma rotina de inicialização da biblioteca de vínculo dinâmico (DLL) falhou. \?\C:\projeto\meia-maratona-electron\node_modules\serialport\build\Release\serialport.node at Error (native) at process.module.(anonymous function) as dlopen at Object.Module._extensions..node (module.js:440:18) at Object.module.(anonymous function) as .node at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:16:19) at bindings (C:\projeto\meia-maratona-electron\node_modules\bindings\bindings.js:76:44) at Object. (C:\projeto\meia-maratona-electron\node_modules\serialport\serialport.js:16:44)

What can i do for this?

"electron-prebuilt": "^0.37.4" "serialport": "2.0.7-beta5" node version : 5.10.1 npm version : 3.8.6 python version: 2.7.11

reconbot commented 8 years ago

@gohackfelipe Can you try serialport@2.1.0 and then run electron-rebuild after installing?

gohackfelipe commented 8 years ago

Hi @reconbot ..

I did what you asked for and did not work.. The same issue is happening...

Error: Uma rotina de inicialização da biblioteca de vínculo dinâmico (DLL) falhou. \?\C:\projeto\meia-maratona-electron\node_modules\serialport\build\Release\serialport.node at Error (native) at process.module.(anonymous function) as dlopen at Object.Module._extensions..node (module.js:440:18) at Object.module.(anonymous function) as .node at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:16:19) at bindings (C:\projeto\meia-maratona-electron\node_modules\bindings\bindings.js:76:44) at Object. (C:\projeto\meia-maratona-electron\node_modules\serialport\serialport.js:16:44)

reconbot commented 8 years ago

Do you have the output of the rebuild?

On Tue, Apr 19, 2016, 6:03 PM Felipe Ribeiro notifications@github.com wrote:

Hi @reconbot https://github.com/reconbot ..

I did what you asked for and did not work.. The same issue is happening...

Error: Uma rotina de inicialização da biblioteca de vínculo dinâmico (DLL) falhou.

\?\C:\projeto\meia-maratona-electron\node_modules\serialport\build\Release\serialport.node at Error (native) at process.module.(anonymous function) as dlopen at Object.Module._extensions..node (module.js:440:18) at Object.module.(anonymous function) as .node at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:16:19)

at bindings (C:\projeto\meia-maratona-electron\node_modules\bindings\bindings.js:76:44)

at Object. (C:\projeto\meia-maratona-electron\node_modules\serialport\serialport.js:16:44)

You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/voodootikigod/node-serialport/issues/538#issuecomment-212147836

gohackfelipe commented 8 years ago

Looks like that i have another problem when i try to execute the electron-rebuild

PS C:\projeto\meia-maratona-electron> .\node_modules\.bin\electron-rebuild.cmd

> nslog@3.0.0 install C:\projeto\meia-maratona-electron\node_modules\nslog
> node-gyp rebuild

C:\projeto\meia-maratona-electron\node_modules\nslog>if not defined npm_config_node_gyp (node "C:\projeto\meia-maratona
electron\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebui
d )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  main.cc
  nslog_win.cc
  win_delay_load_hook.c
LINK : fatal error LNK1104: cannot open file 'libcpmt.lib' [C:\projeto\meia-maratona-electron\node_modules\nslog\build\
slog.vcxproj]

npm WARN prefer global npm@3.8.6 should be installed with -g
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\projeto\meia-maratona-electron\node_modules\npm\node_modules\node-gyp\lib
build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:100:13)
gyp ERR! stack     at ChildProcess.emit (events.js:185:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\projeto\\meia-maratona-electron\\node_modules\\npm\\node_mo
ules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\projeto\meia-maratona-electron\node_modules\nslog
gyp ERR! node -v v5.10.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\projeto\\meia-maratona-electron\\node_modules\\npm\\bin\\npm-c
i.js" "rebuild" "--runtime=electron" "--target=0.37.6" "--arch=x64"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! nslog@3.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nslog@3.0.0 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the nslog package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs nslog
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls nslog
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\projeto\meia-maratona-electron\node_modules\npm-debug.log

Process exited with code: 1
Error: Process exited with code: 1
    at ChildProcess.<anonymous> (C:\projeto\meia-maratona-electron\node_modules\electron-rebuild\lib\spawn.js:55:26)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
andrewjaykeller commented 8 years ago

Can we ship all the binaries with serialport some how? When we package these electron appson OS X for say windows or linux, I see an error where the correct serialport.node version is not found. We can hot fix this by installing the correct serialport version but it's entirely based on your system.

andrewjaykeller commented 8 years ago

What tells serialport to build 47 instead of 46? I would really love some clarity on that.

reconbot commented 8 years ago

Whichever node is doing the compiling. If you're using electron rebuild you'll get the version it provides, if you're doing npm rebuild you'll get the version of your nodejs.

mikew commented 8 years ago

I'm getting a different error, something about the tools version and msbuild:

$ ./node_modules/.bin/electron-rebuild.cmd --force --pre-gyp-fix

...

MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "14.0", "4.0".

npm WARN prefer global npm@3.8.8 should be installed with -g
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\mike\Desktop\dronefuse-client\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:100:13)
gyp ERR! stack     at ChildProcess.emit (events.js:185:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)
gyp ERR! System Windows_NT 10.0.10586
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mike\\Desktop\\dronefuse-client\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\mike\Desktop\dronefuse-client\node_modules\nslog
gyp ERR! node -v v5.10.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mike\\Desktop\\dronefuse-client\\node_modules\\npm\\bin\\npm-cli.js" "rebuild" "--runtime=electron" "--target=0.37.8" "--arch=x64"

Same error with node-pre-gyp rebuild

Versions:

Everything works peachy on the OS X side of things, at least.

jacobq commented 8 years ago

@mikew You might want to try installing MS Visual Studio Express / Community (free version) instead of their BuildTools package. I'm not an expert by any means but have found that to be the most reliable way to get gyp to build things right on Windows. https://github.com/chjj/pty.js/issues/60#issuecomment-85797012

mikew commented 8 years ago

@jacobq yep, seems to be the case.

Wish I knew what component of VS is actually needed, because the build succeeds before VS Community 2015 is finished installing.

reconbot commented 8 years ago

On downloading all the binaries (cc @pushtheworldllc @techninja and others)

We're currently using bindings to find and require the binary and we're placing the binary in the standard location /build/{configuration}/serialport.node (where configuration is usually Release).

For node binaries. What would work perfectly would be if you removed the downloaded binary from /build/Release/ and download all the available binaries and put them in

/compiled/{ABI version}/{platform}/{arch}/

We already name the files with the right information eg serialport-v3.1.1-node-v11-darwin-x64.tar.gz or serialport-v3.1.1-node-v48-win32-x64.tar.gz.

I'd be happy to merge a utility script that does that so you could type npm run download-all-precompiled-binaries and then be set for all platforms when running node.

Electron binaries will work with that directory structure too. I don't know how to prebuild them for download but if you build them and move them to the right location the app will function and you can ship multiple platforms at one time.

paulolc commented 8 years ago

The node-pre-gyp reveal output from a successful compilation of serialport for Electron 1.1.0 (node 6.1.0, Chromium 50.0.2661.102) on Win7x64 indicates "node-v43" for the "node_abi".

$node_modules\.bin\node-pre-gyp.cmd reveal --target=1.1.0 --arch=x64 --dist-url=https://atom.io/download/atom-shell
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.6.28
node-pre-gyp info using node@6.1.0 | win32 | x64
{
  "name": "serialport",
  "configuration": "Release",
  "module_name": "serialport",
  "version": "3.1.2",
  "prerelease": "",
  "build": "",
  "major": 3,
  "minor": 1,
  "patch": 2,
  "runtime": "node",
  "node_abi": "node-v43",
  "target": "1.1.0",
  "platform": "win32",
  "target_platform": "win32",
  "arch": "x64",
  "target_arch": "x64",
  "module_main": "./lib/serialport",
  "toolset": "",
  "host": "https://github.com/voodootikigod/node-serialport/releases/download/3.1.2/",
  "module_path": "E:/mbot/electron-serialport/electron-quick-start/node_modules/serialport/build/Release",
  "module": "E:/mbot/electron-serialport/electron-quick-start/node_modules/serialport/build/Release/serialport.node",
  "remote_path": "",
  "package_name": "serialport-v3.1.2-node-v43-win32-x64.tar.gz",
  "staged_tarball": "build/stage/serialport-v3.1.2-node-v43-win32-x64.tar.gz",
  "hosted_path": "https://github.com/voodootikigod/node-serialport/releases/download/3.1.2/",
  "hosted_tarball": "https://github.com/voodootikigod/node-serialport/releases/download/3.1.2/serialport-v3.1.2-node-v43-win32-x64.tar.gz"
}
node-pre-gyp info ok
paulolc commented 8 years ago

I've forked and adapted the electron-quick-start app to get the latest Electron to 'npm install' with serialport. Check electron-quick-start-serialport. (tested in Win7x64 with node 6.1.0)

To test #812 it's just a matter to check if the serialport binaries fail to download (as they currently do not exist) and falls back to building it.

reconbot commented 8 years ago

https://github.com/electron-userland/electron-packager/issues/359

andresfuseau commented 8 years ago

Hi.. I get this error when trying to open electron app using serialport. Any idea of what could be wrong? If there's a solution could you please explain step by step...

Thanks error

jacobq commented 8 years ago

@andresfuseau I believe that most likely means that the module was not (re)built properly for the node version used by electron. I would suggest removing the files node_modules/serialport/build/Release/* then using node_modules/.bin/electron-rebuild -e node_modules/electron-prebuilt -f to rebuild it. (I assume you have installed electron-rebuild in the project.)

andresfuseau commented 8 years ago

@jacobq Thanks for your help but still don't get it. I already succesfully installed electron-rebuild and deleted the files in node_modules/serialport/build/Release/* .. in which folder should I run node_modules/.bin/electron-rebuild -e node_modules/electron-prebuilt -f?? If I run it on ./.bin folder I get: Unable to find electron-prebuilt's version number, either install it or specify an explicit version Tried also running in my app root and get this: C:\Users\Andr�s\AppData\Roaming\npm\node_modules\electron-rebuild\lib\headers.node-gyp\iojs-1.1.1\Release\iojs.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x1C6A76 [C:\Users\Andr�s\AppData\Roaming\npm\node_modules\electron-rebuild\node_modules\nslog\build\nslog.vcxproj

jacobq commented 8 years ago

@andresfuseau, yes, run in project root. You're getting closer. It looks like electron-rebuild is not working because of your build tools being messed up or something. Could it perhaps be related to the special character in the pathname? Windows is super fussy about that kind of thing.

reconbot commented 8 years ago

Anyone here ever see anything like #838 before? I'm stabbing in the dark trying to debug.

danielmapar commented 8 years ago

I read this post, but I am still facing the DLL issue.

My project uses electron, react/redux and an external library from Particle.io (IOT company).

Whenever I build it on my mac it works 100%, but I am struggling with Windows 10.

Project code: https://github.com/SmartPowerSocket/DesktopApp

img_2830

test

I got Visual Studio Community 2013, Python 2.7 and Node 6.20 installed on my Windows 10 machine.

This project got two node_modules folder. Having said that, one is for the electron + react/redux app, the other is for the particle library.

Any tips?

arve0 commented 8 years ago

Had a hard time figuring this out, electron-rebuild did not work.

Solution

  1. Add this npm script to package.json:
    "postinstall": "cd node_modules/serialport && ./node_modules/.bin/node-pre-gyp rebuild --target=1.3.1 --arch=x64 --dist-url=https://atom.io/download/atom-shell",
  1. Make sure to edit --target=x.x.x to match your version of electron-prebuilt.
  2. Reinstall.
rm -fr node_modules
npm install

OS X: 10.11.6 serialport: 4.0.1 electron-prebuilt: 1.3.1

mariotacke commented 8 years ago

@arve0, you are a life saver. I spent a good 2 hours on this trying to figure out how to build the lib for the new electron version... Thanks.

reconbot commented 8 years ago

I'd gladly accept a PR to add some docs around this. I'm not very familiar with electron so I don't want to be the one writing the docs. Happy to help edit and review.

-Francis

mikew commented 8 years ago

I'm not sure why people are having issues with electron-rebuild. We're using it fine on OS X and Windows with node-serialport:

node_modules/.bin/electron-rebuild --force --pre-gyp-fix --which-module serialport --module-dir electron-app/node_modules

Change electron-app/node_modules to the path of node_modules for your electron app. So if you're only using one package.json it would be node_modules. If your package.json for electron is at some/dir/package.json then you want some/dir/node_modules.

Here is our script to install dependencies for reference: https://gist.github.com/mikew/77259047ef31a2e49b124ff8b29a9745

andrewjaykeller commented 8 years ago

I'm still having horrific build issues. I left it alone for a couple weeks and will try all these new attempts. I'm trying to use serial port in the main provess, anyone else too?

arve0 commented 8 years ago

I'm not sure why people are having issues with electron-rebuild. We're using it fine on OS X and Windows with node-serialport:

@mikew Well, in my case, it was that my installed node version was on an older v8 (or node?) version than electron, which caused (I think) a mismatch in module version packaging. I got an error like this:

Error: Module version mismatch. Expected 49, got 48.

Will node_modules/.bin/electron-rebuild --force --pre-gyp-fix --which-module serialport --module-dir electron-app/node_modules fix that? Might be that you are on an older version of electron that matches your node version?

To be clear, the electron version must match the installed node version. If not, explicit tell the compiler where to find headers and to which version to build.

andrewjaykeller commented 8 years ago

@mikew i tried with electron-rebuild any ideas?

electron-serialport-failure

andrewjaykeller commented 8 years ago

Then i tried dragging and dropping in the downloaded Release from the releases page and got this error: electron-serialport-failure2

muyids commented 8 years ago

I have the same issue with @aj-ptw, I package my electron-serialport app on MAC OSX, it's nomal, then, I run it on win32 x64, the issue happened, 63de5c1431fa7c14174418e89f589431

muyids commented 8 years ago

Here is my package.json

{
  "name": "tool",
  "version": "1.0.0",
  "description": "tool",
  "main": "main.js",
  "scripts": {
    "install": "node-pre-gyp install --fallback-to-build --runtime=electron --target=1.3.3 --target_arch=x64 --directory=./node_modules/serialport --update-binary --dist-url=https://atom.io/download/atom-shell",
    "start": "electron main.js",
    "package-win32": "electron-packager ./ tool --prune --ignore=dist --platform=win32 --arch=x64 --overwrite --out ./dist"
  },
  "devDependencies": {
    "electron-prebuilt": "^1.3.3",
    "node-gyp": "^3.4.0",
    "node-pre-gyp": "^0.6.29"
  },
  "dependencies": {
    "serialport": "^4.0.1"
  },
  "engine": "^6.3.1"
}
andrewjaykeller commented 8 years ago

@dfsq1311 i'm still getting it ha, wish i could shed some light for you!

muyids commented 8 years ago

@aj-ptw I'm also getting it. I'm building it on win32 x64.

muyids commented 8 years ago

when I build on windows platform, I get the error "Release\iojs.lib : fatal error LNK1107".

the issue I submit https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/912

andrewjaykeller commented 8 years ago

I'm having a lot of luck with two package.jsons And using electron-builder also using appvoyer to build for windows.

vicatcu commented 8 years ago

@aj-ptw can you provide a link to a project example on github, I've just recently started liking at appveyor and electron-builder and managed to get a really bare bones project to deploy an installer into a drafted release, but haven't breached including serialport (our anything really) yet. An example would be super helpful, as electron-builder docs, while good, assume a fair bit of knowledge about how everything interacts.

andrewjaykeller commented 8 years ago

I've just recently started liking at appveyor and electron-builder and managed to get a really bare bones project to deploy an installer into a drafted release

@vicatcu cool i hope to be there soon!

For starters I am using Electron React Boilerplate and am using this pull request with electron-builder

The critical components so far are using two package.jsons, the important one is the static/package.json file which contains the module (openbci) which is dependent on node-serialport.

Ok so for some magic I we bring in webpack. Electron with webpack leads to separation of main and renderer processes. Where main is the main.js and renderer is bundle.js. I use openbci in the main process, not the render, but anyway I add serialport to the noParse array and openbci to the externals array.

    module: {
        noParse: [/serialport/]
    },
    externals: [
        'openbci'
    ]

I am pretty sure that's everything!

one0410 commented 8 years ago

If you got the DLL issue, that means you didn't compile the source well. I use the following steps to get it work under my Windows 10 x64

  1. first delete c:\temp\electron\node_modules\serialport\build\Release*
  2. cd c:\temp\electron\node_modules\serialport
  3. ...bin\node-gyp rebuild --target=1.3.4 --arch=x64 --dist-url=https://atom.io/download/atom-shell

Then you can see the binary files in the Release folder. ( where c:\temp\electron is my project folder)

My package.json ->

"devDependencies": { "electron-prebuilt": "^1.3.4", "electron-rebuild": "^1.2.0", "node-gyp": "^3.4.0", "node-pre-gyp": "^0.6.29", "serialport": "^4.0.1" }

bhaveshgohel commented 8 years ago

Thank you so much @arve0 for the solution. Worked like charm! :tada:

Environment: Windows 7 x64. + Node.js v4.5.0 + npm v3.10.6 + electron v1.3.4 + serialport v4.0.1

ghost commented 8 years ago

For those of you with the "Module version mismatch" errors on Windows, make sure you have the correct electron runtime set as the --target= parameter. This will display on the index.html page if you use the starter template. For example, if you are using 1.4.1 then you will need to run this:

node_modules\serialport\node_modules\node-pre-gyp\bin\node-pre-gyp install --fallback-to-build --runtime=electron --target=1.4.1 --target_arch=x64 --directory=node_modules/serialport/ --update-binary --dist-url=https://atom.io/download/atom-shell

spiraljacobs commented 8 years ago

Managed to get serialport working in Electron after trying a number of things. Well, I thinkthink it's working - it's not crashing, or behaving oddly as of yet. Prior to this, the errors/problems that I would get would be: - "Specified procedure not found," error on startup

My System: Windows 10 Anniversary x64 Node: v6.2.2 32 bit. Electron 32 bit.

My package.json (the relevant parts): "devDependencies": { "electron-prebuilt": "^1.3.4", "node-gyp": "^3.4.0", "node-pre-gyp": "^0.6.29", "serialport": "^4.0.1" } serialport will move into the Dependencies, but that's beside the point.

  1. Set environment variables set npm_config_disturl=https://atom.io/download/atom-shell set npm_config_target=1.4.0 set npm_config_arch=ia32 set npm_config_runtime=electron set HOME="C:\Users\me.electron-gyp" set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
  2. Deleted the node_modules\serialport directory
  3. npm install serialport --build-from-source
Ciantic commented 8 years ago

Here is the full trick list I had to do:

  1. npm install electron --save-dev
  2. Install Python2.7 to PATH
  3. Have Visual Studio 2015 installed with C++ tools
  4. set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\
  5. npm install -g node-gyp
  6. npm install ffi --save-dev
  7. npm install serialport --save-dev
  8. npm install electron-rebuild --save-dev
  9. .\node_modules\.bin\electron-rebuild
  10. del .\node_modules\nslog\build\Release\nslog.node (Previous stage should give error)
  11. bash (ubuntu on windows, removing recursively is not something I do from cmd)
  12. rm -rf node_modules/serialport/build/Release/*
  13. rm -rf node_modules/ffi/build/Release/*
  14. exit (return to command prompt)
  15. .\node_modules\.bin\electron-rebuild

I must say, that the tricks one has to do get native modules working with Electron in Windows is so complicated, that it kind of ruins the npm install when it just doesn't work.

I don't know what is a good solution for woes of Windows, but usually if it's possible things should be prebuilt for Windows, it's so damn tricky to rebuild stuff with it sometimes.

jbarguil commented 8 years ago

I'm adding what I had to do:

  1. Install electron-rebuild: npm install --save-dev electron-rebuild.
  2. Manually remove the node_modules/serialport/build/ folder.
  3. Check electron version with electron -v.
  4. Rebuild: npm rebuild serialport --runtime=electron --target=<your-electron-version> --arch=x64 --dist-url=https://atom.io/download/atom-shell.
bhaveshgohel commented 8 years ago

This is what i did to make it work:

1) Install node-pre-gyp globaly:

npm install -g node-pre-gyp

2) Add this to your package.json

"scripts": {
    "start": "electron .",
    "postinstall": "cd node_modules/serialport && node-pre-gyp rebuild --target=1.3.4 --arch=x64 --dist-url=https://atom.io/download/atom-shell",
    "rebuild:64": "cd node_modules/serialport && node-pre-gyp rebuild --target=1.3.4 --arch=x64 --dist-url=https://atom.io/download/atom-shell",
    "rebuild:32": "cd node_modules/serialport && node-pre-gyp rebuild --target=1.3.4 --arch=ia32 --dist-url=https://atom.io/download/atom-shell"
  }

Note: change --target= electron-version-you-use

3) Install serialport

npm install -g serialport

By default it will install x64 version build of serialport as i set in postinstall script.

Now when you want to switch to 32bit build just fire below command.

npm run rebuild:32

Hope this helps someone. Good Luck. :+1: