diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js index bf010ec9..c20150f6 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -481,11 +481,7 @@ class ResolutionRequest { potentialModulePath, ); if (realModuleName === false) { - return this._loadAsFileOrThrow( - ResolutionRequest.EMPTY_MODULE, - fromModule, - toModuleName, - ); + return this._getEmptyModule(fromModule, toModuleName); } return tryResolveSync( @@ -501,11 +497,7 @@ class ResolutionRequest { const realModuleName = this._redirectRequire(fromModule, toModuleName); // exclude if (realModuleName === false) { - return this._loadAsFileOrThrow( - ResolutionRequest.EMPTY_MODULE, - fromModule, - toModuleName, - ); + return this._getEmptyModule(fromModule, toModuleName); } if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) { @@ -720,6 +712,19 @@ class ResolutionRequest { return resolver.tryToResolveFileName(fileName) ? fileName : null; } + _getEmptyModule(fromModule: TModule, toModuleName: string): TModule { + const {moduleCache} = this._options; + const module = moduleCache.getModule(ResolutionRequest.EMPTY_MODULE); + if (module != null) { + return module; + } + throw new UnableToResolveError( + fromModule, + toModuleName, + "could not resolve `${ResolutionRequest.EMPTY_MODULE}'", + ); + } + _loadAsDir( potentialDirPath: string, fromModule: TModule,