Skip to content

Commit 1034587

Browse files
richardlauitaloacasas
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 <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: João Reis <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 1dff218 commit 1034587

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/module.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,16 @@ Module._initPaths = function() {
617617
homeDir = process.env.HOME;
618618
}
619619

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

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

0 commit comments

Comments
 (0)