execa: execa does not respect $PATH variable

I have two installations of git and execa seems to pick the wrong one, not respecting $PATH correctly, while child-process does it correctly (even if I explicitly remove /usr/bin from $PTAH and add my desired path twice, once in the beginning and once in the end):

$ /usr/bin/git --version 
git version 1.8.3.1
$ /opt/rh/rh-git29/root/usr/bin/git --version
git version 2.9.3
$ echo $PATH
/opt/rh/rh-git29/root/usr/bin:/bin:/usr/local/bin:/opt/rh/rh-git29/root/usr/bin
$ cat ./index.js
const execa = require('execa');
(async () => {
    const {stdout} = await execa('git', ['--version']);
    console.log(stdout);
    //=> 'unicorns'
})();
const execFile = require('child_process').execFile;
const child = execFile('git', ['--version'], (error, stdout, stderr) => {
    if (error) {
        console.error('stderr', stderr);
        throw error;
    }
    console.log('stdout', stdout);

});
$ node ./index.js
git version 1.8.3.1
stdout git version 2.9.3

I am missing something here?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

@lucasbraun If I understood your problem correctly, using the preferLocal: false option should solve it, could you confirm this?

We are considering changing its default value from true to false (#314).

@ammarbinfaisal childProcess.spawn() is the base for all other childProcess methods variants including execFile(). See the Node.js source.