Tracking Electron support
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?
Same here
I just got my electron today will investigate!
what version of node are you using?
Chris Williams
@voodootikigod http://twitter.com/voodootikigod | GitHub http://github.com/voodootikigod
The things I make that you should check out: SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ | RobotsConf http://robotsconf.com/ | RobotsWeekly http://robotsweekly.com/
Help me end the negativity on the internet, share this http://jsconf.eu/2011/an_end_to_negativity.html.
On Thu, Jun 4, 2015 at 11:05 AM, Gianluca Bonacin [email protected] wrote:
Same here
— Reply to this email directly or view it on GitHub https://github.com/voodootikigod/node-serialport/issues/538#issuecomment-108927479 .
- Node version: 0.12.4
- Electron version: 0.27.2
The code is simply a boilerplate:
var app = require("app");
var BrowserWindow = require("browser-window");
var mainWindow = null;
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("ready", function () {
mainWindow = new BrowserWindow({
width: 960,
height: 600
});
mainWindow.loadUrl("file://" + __dirname + "/index.html");
mainWindow.on("closed", function () {
mainWindow = null;
});
mainWindow.openDevTools();
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("TODO-TODO-EL-MEXICO!", {
baudrate: 57600
});
});
Same here
I am using Ubuntu 14.04 LTS. I got this when I require serialport when i run in electron.
[3512:0609/164117:INFO:CONSOLE(326)] "Uncaught Error: Cannot find module './node_modules/serialport/build/serialport/v1.4.10/Release/node-v43-linux-x64/serialport.node'", source: module.js (326)
I didn't found this folder but I found './node_modules/serialport/build/serialport/v1.4.10/Release/node-v11-linux-x64/serialport.node'
Node version: 0.10.25 Electron version: 0.27.2
Actually when I renamed the folder to ''node-v43-win32-ia32', this error shown:
Uncaught Exception: Error: Invalid Access to Memory Location
maybe there is something wrong in the native module (serialport.node)
I rename the folder too, and I get this:
[3827:0609/165900:INFO:CONSOLE(134)] "Uncaught Error: Module did not self-register.", source: ATOM_SHELL_ASAR.js (134)
I have same issue.
When I installed serialport, it created folder 'node-v14-win32-x64' instead of 'node-v43-win32-ia32
Windows7 64bit node version : 0.12.4
Hey guys, apparently @usefulthink was able to get this to work by just changing how node-serialport built. I'm using it in my Electron setup right now and it's working well. Here's the link to the commit/fork:
https://github.com/usefulthink/node-serialport/commit/c5aace891834bd7b9b94f72e4420554721026a4f
I've tried @usefulthink's commit, the folder problem is solved but my electron app still show this error:
Uncaught Exception: Error: Invalid Access to Memory Location
The error comes from the binary (serialport.node), I wonder why. Maybe this is because I use Microsoft Visual Studio 2012. If that's true, which version should I use?
I didn't really test anywhere except for OSX 10.10 which was all that I needed. But as all I did was replacing node-pre-gyp with node-gyp that is from my understanding unlikely to be the problem.
Unfortunately, its several years since I last worked with Windows, so no idea..
I couldn't find anything about it here, but that might cause such a problem - did you use electron-rebuild to recompile the add-on?
yes, I've used electron-rebuild but the error still appeared
Hey All, so the @usefulthink fork actually provided me with the insight into what is going with this and I would like to share it so everyone can understand it.
Originally, node-serialport (this module) used a project called node-gyp directly to provide the instructions for compiling the module on various platforms (Windows, Mac, Linux, etc.). While it worked (assuming all necessary dependencies) it was a nightmare as for doing any form of mass installation because undoubtably the necessary dependencies (build tools, compiler, etc) were never installed. This project, node-serialport, quickly became swamped with tickets about how to install on Windows, Mac, and Linux.
Due to this, we moved to using a project called node-pre-gyp, which allowed us to utilize pre-compiled binaries if they exist from a known location and fallback to the local build process if they do not. This was hooked into an elaborate build system using Travis-CI and AppVeyor to generate the necessary compiled versions for Windows, Mac, and Linux on each release published to npm.
Things were happy at this point since people using Windows, Mac, and Linux without the build components could easily use node-serialport without even being aware of its native module nature.
During this time period, the project formerly named node-webkit, now nw.js, started to evolve and gain traction. It utilized its own derivative fork/hack from node-gyp in order to build the necessary native componets which was named nw-gyp and this choice had ramifications that affected the compilation of other native modules. Needless to say, as people began trying to use it in combination with the node-serialport project things did not work smoothly. Until the NW.js team published the previously linked instructions for node-gyp and node-pre-gyp, this project was blamed for incompatibility and many issues were filed.
Then the Atom editor was released. The Electron team that maintains the application framework around the Atom Editor updated to the latest version of Chromium around September, 2014, which consequentially broke compatibility with any and all node-gyp compiled modules. Similar to NW.js, the Electron team posted details about how build Electron with other native modules, but those native modules mostly were not aware of this. As such, many issues were filed against this and other project concerned about the compatibility of that project when they try to integrate with Electron.
The general node.js leadership has not openly discussed this mainly because they do not maintain end-user facing native modules, honestly there aren't a tremendous number of them. For those of us that do maintain a native module, the constant hamster wheel is enough to drive one insane. Until a maintainer can explore the other project, there is a very real sense that it could be the fault/issue/incompatibility of the project being maintained since Node.js, io.js and the ecosystem changes so quickly and its too much to keep up with. At this point, here is the general state of the world:
- node-gyp is the de-facto build standard for Node.js and native modules. All things should be compatible with node-gyp at a minimum or else it should be considered out of compliance.
- node-pre-gyp since it is an enhancement beyond node-gyp by adding pre-compilation and retrieval, it should be considered as part of the compliance suite for any native module.
- nw-gyp to my knowledge is only used by NW.js and as such should ensure that it or application that includes does not break compliance with node-gyp or node-pre-gyp. That is currently not the case however and inclusion of node-gyp and node-pre-gyp modules still require special handling.
- Atom-Shell/Electron is currently not compliant with node-pre-gyp due to the way that it identifies its node execution version and environment. That said, the node-pre-gyp maintainers are working on a way to make node-pre-gyp modules work with Electron. There is currently an outstanding pull request that will provide support for this variation handling. Until that pull request is merged in, continue to use the instructions provided by the Electron team.
Specifically for node-serialport, as the prime maintainer I will not be merging in modifications that take this project backwards (ala reverting to node-gyp). Also, I will not be integrating special cases to support new native environments that have broken compatibility without thorough testing in every execution environment we already support.
In summary, maintaining a native module in node.js is a constant battle. The node community needs to hold projects that break native compilation compatibility accountable by encouraging those projects to ensure node-gyp and node-pre-gyp modules can still be included without issue or failure.
Thank you so much for writing this! Fully agree.
@voodootikigod I agree too, I think it makes sense for node-pre-gyp to resolve the issue on their side rather than you changing your project. In the meantime the work @usefulthink should get us by.
@usefulthink @a-giovani17 Windows compiling does work, as that's where I'm doing my build. I'm using the 2013 compiler "--msvs_version=2013", with electron-rebuild for compiling running the command ".\node_modules.bin\electron-rebuild . --version=0.28.3". That downloads the 0.28.3 headers for electron and compiles against them.
Granted, I've done a lot of other things to my setup environment. If you wiped my computer and told me to get it all working again at this point I would likely be doomed. :P
@usefulthink just want to make sure the 'going backwards' is not a knock on you by any means (I like your solution in the short run :+1:). Cheers!
@voodootikigod no worries, I just needed it to work and did the ugliest hack I could think of. I wouldn't have thought of making a PR of it anyway, and I agree with you that this would indeed be moving backwards for this project :)
I am struggeling a bit to find out what the compatible Electron prebuilt version is and I suspect it is related to this issue. Are you using 0.27.2 because that is the last compatible version (uses iojs v1)? Or is serialport or the @usefulthink his fork also compatible with iojs v2 and Electron > 0.27?
I have tested serialport with iojs-v2 (without electron) and that seemed to work just fine, but somehow in combination with electron I haven't managed to make it work with versions > 0.27
Also running .\node_modules\.bin\electron-rebuild doesn't seem to do much. Is that command supposed to finish in a split second?
Hi @0x80, you should be able to install my forked-version with npm install serialport-electron, then electron-rebuild --force should do the trick (i don't really know how electron-rebuild determines what to rebuild, but you will see the usual compiler-output when it does). This should work in every node/iojs-version that is supported by this module, as it will always rebuild from source.
I guess you just have to try it.
@usefulthink thanks! I've managed to make it work with 0.29.1. Your module didn't seem to be available in npm registry so I installed if from git.