mirror of https://github.com/status-im/metro.git
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:
parent
e5197e940e
commit
2bec70bf7d
|
@ -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__) {
|
||||
|
|
Loading…
Reference in New Issue