Skip to content

Commit ba91c41

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 <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: João Reis <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 1dc6b38 commit ba91c41

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
@@ -453,7 +453,16 @@ Module._initPaths = function() {
453453
homeDir = process.env.HOME;
454454
}
455455

456-
var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
456+
// $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
457+
var prefixDir;
458+
// process.execPath is $PREFIX/bin/node except on Windows where it is
459+
// $PREFIX\node.exe.
460+
if (isWindows) {
461+
prefixDir = path.resolve(process.execPath, '..');
462+
} else {
463+
prefixDir = path.resolve(process.execPath, '..', '..');
464+
}
465+
var paths = [path.resolve(prefixDir, 'lib', 'node')];
457466

458467
if (homeDir) {
459468
paths.unshift(path.resolve(homeDir, '.node_libraries'));

0 commit comments

Comments
 (0)