Skip to content

Commit 9f804d1

Browse files
committed
bootstrap: 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' ```
1 parent 3adec43 commit 9f804d1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/internal/bootstrap/loaders.js

Lines changed: 3 additions & 0 deletions
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)