diff --git a/crates/swc_ecma_transforms_module/src/path.rs b/crates/swc_ecma_transforms_module/src/path.rs index 3f74d07bc723..7c33109ef781 100644 --- a/crates/swc_ecma_transforms_module/src/path.rs +++ b/crates/swc_ecma_transforms_module/src/path.rs @@ -193,13 +193,8 @@ where target_path.display().to_string().into() } } -} -impl ImportResolver for NodeImportResolver -where - R: Resolve, -{ - fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result { + fn try_resolve_import(&self, base: &FileName, module_specifier: &str) -> Result { let _tracing = if cfg!(debug_assertions) { Some( tracing::span!( @@ -316,6 +311,19 @@ where } } +impl ImportResolver for NodeImportResolver +where + R: Resolve, +{ + fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result { + self.try_resolve_import(base, module_specifier) + .or_else(|err| { + warn!("Failed to resolve import: {}", err); + Ok(module_specifier.into()) + }) + } +} + macro_rules! impl_ref { ($P:ident, $T:ty) => { impl<$P> ImportResolver for $T