Don't swallow the error if a module require fails

Reviewed By: davidaurelio

Differential Revision: D4733269

fbshipit-source-id: 2cca14c023b148b62cf24f204cdb355f8d2f3590
This commit is contained in:
Marc Horowitz 2017-03-20 12:56:30 -07:00 committed by Facebook Github Bot
parent e5197e940e
commit 2bec70bf7d
1 changed files with 5 additions and 3 deletions

View File

@ -38,6 +38,7 @@ type ModuleDefinition = {|
exports: Exports,
factory: FactoryFn,
hasError: boolean,
error?: any,
hot?: HotModuleReloadingData,
isInitialized: boolean,
verboseName?: string,
@ -138,7 +139,7 @@ function loadModuleImplementation(moduleId, module) {
}
if (module.hasError) {
throw moduleThrewError(moduleId);
throw moduleThrewError(moduleId, module.error);
}
// `require` calls int the require polyfill itself are not analyzed and
@ -185,6 +186,7 @@ function loadModuleImplementation(moduleId, module) {
return (module.exports = moduleObject.exports);
} catch (e) {
module.hasError = true;
module.error = e;
module.isInitialized = false;
module.exports = undefined;
throw e;
@ -201,9 +203,9 @@ function unknownModuleError(id) {
return Error(message);
}
function moduleThrewError(id) {
function moduleThrewError(id, error: any) {
const displayName = __DEV__ && modules[id] && modules[id].verboseName || id;
return Error('Requiring module "' + displayName + '", which threw an exception.');
return Error('Requiring module "' + displayName + '", which threw an exception: ' + error);
}
if (__DEV__) {