0rpc / zerorpc-node

zerorpc for node.js
http://www.zerorpc.io
Other
704 stars 166 forks source link

Example code not work in locally #112

Closed o1xhack closed 4 years ago

o1xhack commented 4 years ago

I've create a index.html following:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <title>Hello World!</title>
</head>
<body>
<label for="name"></label><input id="name"/>
<p id="result">Hello: </p>
</body>
<!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>

</html>

And then using the cliend example inside renderer.js:

var zerorpc = require("zerorpc");

var client = new zerorpc.Client();
client.connect("tcp://127.0.0.1:4242");

client.on("error", function(error) {
    console.error("RPC client error:", error);
});

client.invoke("iter", 10, 20, 2, function(error, res, more) {
    if(error) {
        console.error(error);
    } else {
        console.log("UPDATE:", res);
    }

    if(!more) {
        console.log("Done.");
    }
});

(USING CLI terminal)I've successfully adding python running inside main.js that prove by doing npm start then zerorpc tcp://localhost:4242 hello NXB to get the result in terminal.

But the function is not work in the actual electron app. The console log inside renderer.js is not showing anything(as I open the debug window). The debug window shows Uncaught ReferenceError: require is not defined on the code line var zerorpc = require("zerorpc");. So every console.log line before that will give output in debug-console window, and all other console.log is failing, even if it outside the client.connect.

I'm following all the instruction and other articles to setup and install the electron, zerprpc lib. But not found the solution and the reason.

Is this a known issue for the library not support for new electron version?

bombela commented 4 years ago

I do not know much about Electron. As I understand it, it is Google Chrome web browser with some extra javascript APIs to access the filesystem and other more desktop friendly features. zerorpc is a nodejs project. I am not sure it can run within a normal web browser js vm.

o1xhack commented 4 years ago

@bombela Thanks for the quick reply.

I'm exploring to developing electron as GUI and python as the backend, then using zerorpc to connecting them together, This is one of the article https://medium.com/@abulka/electron-python-4e8c807bfa5e. There is not a lot of the articles out, but in the concept it should be fine to work but seems the electron I'm using is failing on some part. That's why I want to check if there is any known dependency issue around.

mknap-dev commented 4 years ago

@o1xhack I also use electron with zerorpc to combine NodeJs with python. Actually it's electron change, please look at: https://stackoverflow.com/questions/44391448/electron-require-is-not-defined

o1xhack commented 4 years ago

@mknap-dev Thanks for point this to me. After I enable this option I did notice the previous message is gone.

However several other errors happened: Uncaught Error: The module '/Users/<usr>/Documents/SyncDrive/POC1/node_modules/zeromq/build/Release/zmq.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 75. Please try re-compiling or re-installing the module (for instance, usingnpm rebuildornpm install).

I've researched on this error and tried several way to rebuild, including manually rebuild but all failes. Did you anything about this? Or, can you tell me which electron version you are using?

And also the (node:21475) Electron: Loading non context-aware native modules in the renderer process is deprecated and will stop working at some point in the future, please see https://github.com/electron/electron/issues/18397 for more information

mknap-dev commented 4 years ago

I had that problem too. You have to rebuild zeroMQ with same version of NodeJs that electron was compiled. Electron provides the tool for that purpose. Try: npx electron-rebuild after npm install.

o1xhack commented 4 years ago

@mknap-dev Yes, that's what I'm understanding. I tried several ways of rebuild process but all failed with error. Wondering if the lastest electron-rebuild have some bug

o1xhack commented 4 years ago

what is the electron version supported for current 0.9.8?

o1xhack commented 4 years ago

It's about the electron version. v6.1.5 rebuild success, v7+ seems fail.