Skip to content

Commit b89f6b1

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
build: avoid swallowing module not found exception
1 parent d9f73d7 commit b89f6b1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/bootstrap-local.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
119119

120120
Module._resolveFilename = function (request, parent) {
121121
let resolved = null;
122+
let exception;
122123
try {
123124
resolved = oldResolve.call(this, request, parent);
124-
} catch (_) {}
125+
} catch (e) {
126+
exception = e;
127+
}
125128

126129
if (request in packages) {
127130
return packages[request].main;
@@ -135,6 +138,12 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
135138
if (match) {
136139
const p = path.join(packages[match].root, request.substr(match.length));
137140
return oldResolve.call(this, p, parent);
141+
} else if (!resolved) {
142+
if (exception) {
143+
throw exception;
144+
} else {
145+
return resolved;
146+
}
138147
} else {
139148
// Because loading `.ts` ends up AFTER `.json` in the require() logic, requiring a file that has both `.json`
140149
// and `.ts` versions will only get the `.json` content (which wouldn't happen if the .ts was compiled to

0 commit comments

Comments
 (0)