Permalink
Browse files

Don't swallow the error if a module require fails

Reviewed By: davidaurelio

Differential Revision: D4733269

fbshipit-source-id: 2cca14c023b148b62cf24f204cdb355f8d2f3590
  • Loading branch information...
mhorowitz authored and facebook-github-bot committed Mar 20, 2017
1 parent ebb55c6 commit d7314661fb4930f0c9e01ccc8de21be1f53d6f54
Showing with 5 additions and 3 deletions.
  1. +5 −3 packager/src/Resolver/polyfills/require.js
@@ -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__) {

0 comments on commit d731466

Please sign in to comment.