wilk / microjob

A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.
https://wilk.github.io/microjob/
MIT License
2.02k stars 47 forks source link

The worker script filename must be an absolute path or a relative path #32

Closed hashtafak closed 5 years ago

hashtafak commented 5 years ago

I see in the code you use const worker = new worker_threads_1.Worker(${dirname}/worker.js); That should be fix to `.Worker(path.resolve(dirname, './worker.js'));`

I'm trying to compile .js into 1 .exe file using nexe then can't run with your current code.

wilk commented 5 years ago

What's the error you get?

hashtafak commented 5 years ago
  1. Test with Node
    $ node --experimental-worker testm
    1000000

I'm using quick example code: https://github.com/wilk/microjob#quick-example

  1. Then complie with nexe

    $ nexe testm.js --enableNodeCli --build --verbose
    i nexe 2.0.0-rc.34
    √ Downloading Node.js source from: https://nodejs.org/dist/v10.15.0/node-v10.15.0.tar.gz
    √ Source already downloaded
    √ Compiling result
    √ Writing result to file
    √ Entry: 'testm.js' written to: testm.exe
    √ Finished in 1.123s
  2. Run complied file

    $ testm --experimental-worker
    TypeError [ERR_WORKER_PATH]: The worker script filename must be an absolute path or a relative path starting with './' or '../'. Received "dist/worker.js"
    at new Worker (internal/worker.js:264:15)
    at Promise (..\testm.exe:212:32)
    at new Promise (<anonymous>)
    at WorkerPool.setup (..\testm.exe:208:16)
    at ..\testm.exe:19:13
    at Object.<anonymous> (..\testm.exe:38:5)
    at c (..\testm.exe:272:3584)
    at Function.r.import (..\testm.exe:272:4190)
    at ..\testm.exe:269:15
    at Object.<anonymous> (..\testm.exe:272:1)
wilk commented 5 years ago

Solved in https://github.com/wilk/microjob/releases/tag/v0.4.2 🎉 Thanks ;)