From 500d17b07198b9e042f9898e650a34b890de70a0 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 25 Oct 2016 23:58:06 +0100 Subject: [PATCH] module: fix loading from global folders on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/9283 Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: João Reis Reviewed-By: Ben Noordhuis --- lib/module.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/module.js b/lib/module.js index f0d149723d8a6c..ea7d61325772f0 100644 --- a/lib/module.js +++ b/lib/module.js @@ -616,7 +616,16 @@ Module._initPaths = function() { homeDir = process.env.HOME; } - var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')]; + // $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation. + var prefixDir; + // process.execPath is $PREFIX/bin/node except on Windows where it is + // $PREFIX\node.exe. + if (isWindows) { + prefixDir = path.resolve(process.execPath, '..'); + } else { + prefixDir = path.resolve(process.execPath, '..', '..'); + } + var paths = [path.resolve(prefixDir, 'lib', 'node')]; if (homeDir) { paths.unshift(path.resolve(homeDir, '.node_libraries'));