From c0529676364db7e34b6788d7c10cec47fd4d3fe0 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 17 Sep 2019 12:45:23 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/29593 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- lib/internal/bootstrap/loaders.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 2889df4812bb03..cc1157a55774e2 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -186,6 +186,9 @@ function nativeModuleRequire(id) { } const mod = NativeModule.map.get(id); + // Can't load the internal errors module from here, have to use a raw error. + // eslint-disable-next-line no-restricted-syntax + if (!mod) throw new TypeError(`Missing internal module '${id}'`); return mod.compile(); }