yao-pkg / pkg

Package your Node.js project into an executable
https://www.npmjs.com/package/@yao-pkg/pkg
MIT License
312 stars 11 forks source link

[BUG] can't run child_process.fork with string code #13

Closed damartripamungkas closed 8 months ago

damartripamungkas commented 8 months ago

What version of pkg are you using?

5.11.0

What version of Node.js are you using?

20.9.0

What operating system are you using?

Mac, Windows, Linux

What CPU architecture are you using?

x64

What Node versions, OSs and CPU architectures are you building for?

node20

Describe the Bug

can't run child_process.fork with string code and parameter { execArgv: ["--eval"] } full code :

const { fork } = require("node:child_process");

const codeStr = `
    setInterval(() => {
        console.log('sub process:' + Math.random())
    }, 1000)
`;

fork(codeStr, { execArgv: ["--eval"] });

error :

node:internal/modules/cjs/loader:1080
  throw err;
  ^

Error: Cannot find module 'C:\custom-main\--eval'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Function.runMain (pkg/prelude/bootstrap.js:1983:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Expected Behavior

can be run

To Reproduce

in above

damartripamungkas commented 8 months ago

solved because I changed the method to worker_thread, not because of anything else