Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How i use node.js worker in nwjs? #7114

Closed
jackieron opened this issue Jul 16, 2019 · 18 comments
Closed

How i use node.js worker in nwjs? #7114

jackieron opened this issue Jul 16, 2019 · 18 comments
Assignees

Comments

@jackieron
Copy link

when i use node.js woker in nwjs, there is an error
Uncaught Error: The V8 platform used by this instance of Node does not support creating Workers.

nwjs version is 0.39.2 win x64

@rogerwang
Copy link
Member

Could you please provide a full sample (not code snippets) so we can reproduce?

@Dimtime
Copy link

Dimtime commented Aug 3, 2019

Could you please provide a full sample (not code snippets) so we can reproduce?

I have same issue:

const { Worker } = require('worker_threads');
let w = new Worker('./worker.js'); //empty file

@Dimtime
Copy link

Dimtime commented Aug 5, 2019

Seems this problem not only with nwjs...
Electron too: electron/electron#18540
Too bad i hoped use them, while this bug not fixed too: #6477

@rogerwang rogerwang self-assigned this Dec 22, 2019
@rogerwang
Copy link
Member

@rogerwang
Copy link
Member

The fix is released in 0.44.0 beta1

@Dimtime
Copy link

Dimtime commented Feb 5, 2020

The fix is released in 0.44.0 beta1

Hm but i dont see how it fixed something...?
Try test code and just get error page:

const { Worker } = require('worker_threads');
let w = new Worker('./worker.js'); //empty file

@rogerwang
Copy link
Member

This works for me:
index.html:

<script>
const wt = require('worker_threads');
let w = new wt.Worker('./worker.js');
</script>

worker.js:

const fs=require('fs');
fs.writeFileSync('output.txt', "hello world");

@TheJaredWilcurt
Copy link
Member

@rogerwang When attempting to validate this fix I found that NW.js 0.44.0 Beta 1 (SDK) crashes when running the above code.

Reproduction:

Tested in Windows 7 64.

@peq42
Copy link

peq42 commented Feb 15, 2020

NW.js 0.44.1 still has this problem (tested on windows 10 64 bits)

or well, more specifically, it crashes the application(closing it completly if I try opening the dev tools to check for errors)

@khoshrou
Copy link

Hi Roger
I am using NW.js 0.44.1 on windows 10 64 bits with a sample as simple as you provided here
It crashes without any indication about what happened.

Untitled

@peq42
Copy link

peq42 commented Feb 23, 2020

@rogerwang any news?

@khoshrou
Copy link

Still Waiting ....

@rogerwang
Copy link
Member

This is fixed in git and will be available in the next nightly build.

@khoshrou
Copy link

I checked simple scenario is working, Thanks

@Dimtime
Copy link

Dimtime commented Feb 26, 2020

I checked simple scenario is working, Thanks

I try check, but have problems...

  1. File created, but with big delay
  2. I cant get messages
//main
worker.on('message', message => console.log(message));   
//worker
const { parentPort } = require('worker_threads');
parentPort.postMessage('test');  

@khoshrou
Copy link

your sample should work, I just tested with roger's sample:

<script>
const wt = require('worker_threads');
let w = new wt.Worker('./worker.js');
</script>

worker.js:

const fs=require('fs');
fs.writeFileSync('output.txt', "hello world");

also tested post message and work data and all work.

@Dimtime
Copy link

Dimtime commented Feb 27, 2020

also tested post message and work data and all work

Thanks for testing, yes it was my mistake... Seems all work
But i have one question and dont know - bug or not (i dont see this in console after):

//worker.js
console.log('test');

@Matt-Maerz
Copy link

Matt-Maerz commented Jun 29, 2023

Hey,
With version 76.1 the app crashes without any errors.
I have used the attached example, just remove the *.txt extension from the files

It is exactly the above example. An HTML and a Server.js is loaded. In the Server.js a WebWorker is called.
The Web Worker writes a txt file with Hello World

index.html.txt
package.json.txt
Server.js.txt
workerFile.js.txt

Can anyone else confirm the behavior, or am I missing something?
Thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants