The module doesn't return the correct path when running as a self-executable process (not directly using node).
This happens due to the usage of process.execPath which is assumed to return node/node.exe but that isn't always the case.
Steps to reproduce:
Install pkg globally: npm i -g pkg
Install global-prefix locally
Create a new file myApp.js, type in console.log(require('global-prefix'))
Run node index.js -> You get something like /usr/bin/ or /Users/MY_USERNAME/.nvm/versions/node/v14.20.0
Now create a self-executable file for the local project: pkg myApp.js -t linux / pkg myApp.js -t macos / whatever..
Run the newly created myApp / myApp.exe -> Unexepected result, something like: C:\Users\myApp.exe. The expected result is the global directory where NodeJS sits.
A proposed solution would be to explicitly search for node executable (like this library does with npm) instead of using process.execPath.
The module doesn't return the correct path when running as a self-executable process (not directly using node). This happens due to the usage of
process.execPath
which is assumed to returnnode
/node.exe
but that isn't always the case.Steps to reproduce:
pkg
globally:npm i -g pkg
global-prefix
locallymyApp.js
, type inconsole.log(require('global-prefix'))
node index.js
-> You get something like/usr/bin/
or/Users/MY_USERNAME/.nvm/versions/node/v14.20.0
pkg myApp.js -t linux
/pkg myApp.js -t macos
/ whatever..myApp
/myApp.exe
-> Unexepected result, something like:C:\Users\myApp.exe
. The expected result is the global directory where NodeJS sits.A proposed solution would be to explicitly search for
node
executable (like this library does withnpm
) instead of usingprocess.execPath
.Pull Request