Skip to content

Commit c052967

Browse files
Fishrock123BridgeAR
authored andcommitted
bootstrap: provide usable error on missing internal module
Due to how bootstrap/loaders.js itself is loaded and invoked, stacktraces from it are munged and no longer point back to the error source. That resulted in the following unhelpful error if an internal module was missing or misnamed: ``` internal/bootstrap/loaders.js:190 return mod.compile(); ^ TypeError: Cannot read property 'compile' of undefined ``` This changes that to at least print the id that was attempted to be loaded: ``` internal/bootstrap/loaders.js:189 if (!mod) throw new TypeError(`Missing internal module '${id}'`); ^ TypeError: Missing internal module 'internal/a' ``` PR-URL: #29593 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 4954792 commit c052967

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/internal/bootstrap/loaders.js

+3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ function nativeModuleRequire(id) {
186186
}
187187

188188
const mod = NativeModule.map.get(id);
189+
// Can't load the internal errors module from here, have to use a raw error.
190+
// eslint-disable-next-line no-restricted-syntax
191+
if (!mod) throw new TypeError(`Missing internal module '${id}'`);
189192
return mod.compile();
190193
}
191194

0 commit comments

Comments
 (0)