vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.27k stars 1.01k forks source link

--options in Windows OS + Cluster #1047

Closed incapdns closed 2 years ago

incapdns commented 3 years ago

The cluster is disconnecting (closing) when using "--options" when compiling with PKG, example: pkg test.js --options max_old_space_size = 4096

Example code:

process.env.UV_THREADPOOL_SIZE = 1024;

const cluster = require('cluster');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
    for (let i = 0; i < numCPUs; i++) {
        cluster.fork()
    }
    cluster.on('exit', () => {
        console.log('Bug PKG !!')
    })
} else {
    console.log('Ok!')
}

Node version: v14.15.5 OS: Windows

It is noticed that this happens only in the cluster (child)

Log:

Error: Cannot find module 'C:\Program Files\VertrigoServ\www\bet365\--max_old_space_size=4096'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1027:15)
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1346:46)
    at Function.Module._load (internal/modules/cjs/loader.js:896:27)
    at Function.Module.runMain (pkg/prelude/bootstrap.js:1375:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Bug PKG !!
incapdns commented 3 years ago

Plz verify linux too.

erossignon commented 3 years ago

Same issue on linux

ashwini-springct commented 3 years ago

Any update on this? We are facing same issue with Node Cluster enabled. When can we expect this fix to be released ?

hacke2 commented 3 years ago

I also encountered the same issue. Is there a temporary plan? Thx

hacke2 commented 3 years ago

Temporary fix:

childProcess.spawn = function spawn() {
    const args = cloneArgs(arguments);
    setOptsEnv(args);
    modifyShort(args);
    // https://github.com/vercel/pkg/issues/1126
    if (args[0] === EXECPATH) {
      // filter
      args[1] = args[1].filter(arg => {
        if ([
          '--no-deprecation',
          '--require',
          'node_modules/source-map-support/register.js',
          '--max_old_space_size',
        ].some(_arg => arg.includes(_arg))) {
          return false;
        }
        return true;
      });
    }
    return ancestor.spawn.apply(childProcess, args);
  };

it can fix #1126 also

hacke2 commented 3 years ago

But the patch code is missing the --require feature

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] commented 2 years ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

lamualfa commented 1 year ago

same issue here.

lamualfa commented 1 year ago

Temporary fix:

childProcess.spawn = function spawn() {
    const args = cloneArgs(arguments);
    setOptsEnv(args);
    modifyShort(args);
    // https://github.com/vercel/pkg/issues/1126
    if (args[0] === EXECPATH) {
      // filter
      args[1] = args[1].filter(arg => {
        if ([
          '--no-deprecation',
          '--require',
          'node_modules/source-map-support/register.js',
          '--max_old_space_size',
        ].some(_arg => arg.includes(_arg))) {
          return false;
        }
        return true;
      });
    }
    return ancestor.spawn.apply(childProcess, args);
  };

it can fix #1126 also

Where should we put this code?

lamualfa commented 1 year ago

For anyone who struggles with this problem, try to install the solved version of pkg directly from this PR https://github.com/vercel/pkg/pull/1462.

NPM

npm install github:bergheim/pkg#forked-runtime-options

PNPM

pnpm add github:bergheim/pkg#forked-runtime-options

After you run one of the commands above, you'll see that the pkg dependency's version will be changed:

package.json

{
  "devDependencies": {
    "pkg": "github:bergheim/pkg#forked-runtime-options"
  }
}