diff --git a/util/ModuleResolution.re b/util/ModuleResolution.re index 7e2ae249..f34efdaf 100644 --- a/util/ModuleResolution.re +++ b/util/ModuleResolution.re @@ -3,10 +3,21 @@ open Infix; let rec resolveNodeModulePath = (~startPath=".", name) => { let path = startPath /+ "node_modules" /+ name; switch (startPath) { - | "/" => Files.exists(path) ? Some(path) : None + | "/" => if (Files.exists(path)) { + Some(path); + } else { + switch (Sys.getenv("NODE_PATH")) { + | node_path => + node_path + |> Str.split(Str.regexp(":")) + |> List.map((path) => Filename.concat(path, name)) + |> List.find_opt((path) => Files.exists(path)); + | exception Not_found => None + }; + }; | _ => Files.exists(path) ? Some(path) : resolveNodeModulePath(~startPath=Filename.dirname(startPath), name) }; -}; \ No newline at end of file +};