You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
PKG_EXECPATH is being set as an environment variable transparently later on in the bootstrap shims:
function setOptsEnv (args) {
var pos = args.length - 1;
if (typeof args[pos] === 'function') pos -= 1;
if (typeof args[pos] !== 'object' || Array.isArray(args[pos])) {
pos += 1;
args.splice(pos, 0, {});
}
var opts = args[pos];
if (!opts.env) opts.env = require('util')._extend({}, process.env);
if (opts.env.PKG_EXECPATH === 'PKG_INVOKE_NODEJS') return;
opts.env.PKG_EXECPATH = EXECPATH;
}
I'm not sure what the intention of deleting the entrypoint argument in the event of self-execution is - I'm sure there's a point that I'm missing.
Note that manually re-inserting the entrypoint as a command line argument works:
./testbin /assets/index.js run
However, the behavior seems odd. I'm working on a command line tool which orchestrates/coordinates commands (think ansible) - and self-invocation of the tool unexpectedly fails due to the above.
We encounter the issue on our side as well. Our workaround was (on Windows, but I think the same would work on other OS) to not directly run the process, but to wrap it with a cmd.exe that would overwrite the PKG_EXECPATH environment variable:
stderr: internal/modules/cjs/loader.js:582
throw err;
^
Error: Cannot find module '/home/eqemu/server/server-launcher'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1287:46)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Function.Module.runMain (pkg/prelude/bootstrap.js:1316:12)
at startup (internal/bootstrap/node.js:320:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:659:3)
Nothing in my code does a require for server-launcher so I was sitting here trying to find some magical require statement where I was passing in something funky. This was incredibly elusive
I was able to combine the suggestions of @matthieukern and @Akkadius into this fairly simple workaround using execa (I'm sure it can be done just using the native child_process as well):
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
work the same way as it does in pure Node, where process.execPath points to Node.
For what it's worth, it turns out the project I'm working on has code that depends on this -- though nobody on the team seems to have connected the dots before someone asked, "wait, how does this work at all", and it took some quite bemused debugging to figure out how pkg didn't break our program.
Activity
jjhesk commentedon Apr 30, 2018
maybe this guy can help
EricMCornelius commentedon May 23, 2018
@igorklopov - is there a reason for the
process.argv.splice(1, 1);removal of a commandline argument when self-executing?tavisrudd commentedon Jun 29, 2018
@igorklopov I'm also running into this bug when trying to upgrade from 4.2.6 on https://github.com/unbounce/iidy which invokes itself. Would you accept a PR that allows us to stop https://github.com/zeit/pkg/blob/20e6d00c5d679e2d29e49f6dfc5cea258cf7d71e/prelude/bootstrap.js#L1336 from passing
PKG_EXECPATHthrough to child procs? Commenting that line out solves the issue for us.tavisrudd commentedon Jun 29, 2018
FYI, I'm only noticing this bug on Linux. The same
iidytests that expose it run fine on macos.chanphillip commentedon Aug 18, 2018
I got the same issue. @tavisrudd 's solution works for my case too!
divyenduz commentedon Sep 17, 2018
I am running into the same issue. Here is a minimal reproduction: https://github.com/divyenduz/pkg-npm-run
Any known workarounds? :)
matthieukern commentedon Nov 26, 2018
We encounter the issue on our side as well. Our workaround was (on Windows, but I think the same would work on other OS) to not directly run the process, but to wrap it with a
cmd.exethat would overwrite thePKG_EXECPATHenvironment variable:Akkadius commentedon Jul 2, 2019
This took care of my issue as well
I spent a few hours on this one, was completely bizarre
My actual error
Nothing in my code does a require for
server-launcherso I was sitting here trying to find some magical require statement where I was passing in something funky. This was incredibly elusivepkg 4.4
node 10.16.0
os Ubuntu 18.04 LTS
edwardfoyle commentedon Nov 24, 2020
I was able to combine the suggestions of @matthieukern and @Akkadius into this fairly simple workaround using execa (I'm sure it can be done just using the native child_process as well):
github-actions commentedon Apr 23, 2021
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 commentedon Apr 29, 2021
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.
hmakholm commentedon May 4, 2021
The intention must be to make
work the same way as it does in pure Node, where
process.execPathpoints to Node.For what it's worth, it turns out the project I'm working on has code that depends on this -- though nobody on the team seems to have connected the dots before someone asked, "wait, how does this work at all", and it took some quite bemused debugging to figure out how pkg didn't break our program.