Skip to content

Commit be5bde0

Browse files
richardlauandrew749
authored andcommitted
module: fix loading from global folders on Windows
Code was calculating $PREFIX/lib/node relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the installed Node.js). PR-URL: nodejs/node#9283 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: João Reis <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 261cbc9 commit be5bde0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/module.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,16 @@ Module._initPaths = function() {
616616
homeDir = process.env.HOME;
617617
}
618618

619-
var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
619+
// $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
620+
var prefixDir;
621+
// process.execPath is $PREFIX/bin/node except on Windows where it is
622+
// $PREFIX\node.exe.
623+
if (isWindows) {
624+
prefixDir = path.resolve(process.execPath, '..');
625+
} else {
626+
prefixDir = path.resolve(process.execPath, '..', '..');
627+
}
628+
var paths = [path.resolve(prefixDir, 'lib', 'node')];
620629

621630
if (homeDir) {
622631
paths.unshift(path.resolve(homeDir, '.node_libraries'));

0 commit comments

Comments
 (0)