diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 9805a1c0c1d..a1b8ebcb81f 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -83,6 +83,9 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) { // the bundled one will be used for installing things. pathArr.unshift(path.join(__dirname, "..", "..", "bin", "node-gyp-bin")) + // prefer current node interpreter in child scripts + pathArr.push(path.dirname(process.execPath)) + if (env[PATH]) pathArr.push(env[PATH]) env[PATH] = pathArr.join(process.platform === "win32" ? ";" : ":") diff --git a/test/tap/lifecycle-path.js b/test/tap/lifecycle-path.js index fae6fcc83f7..39761b48d75 100644 --- a/test/tap/lifecycle-path.js +++ b/test/tap/lifecycle-path.js @@ -67,7 +67,8 @@ test('make sure the path is correct', function (t) { // get the ones we tacked on, then the system-specific requirements var expect = [ '{{ROOT}}/bin/node-gyp-bin', - '{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin' + '{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin', + path.dirname(process.execPath) ].concat(PATH.split(pathSplit).map(function (p) { return p.replace(/\\/g, '/') }))