Skip to content

Commit 500d17b

Browse files
richardlauMylesBorins
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: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 67b6d7d commit 500d17b

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)