From d3299c2d6c036d3f016ef1abbe9c06e9b1656fd0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 28 Nov 2022 17:48:56 -0500 Subject: fix(npm): don't resolve JS files when resolving types (#16854) Closes #16851 --- cli/node/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'cli/node') diff --git a/cli/node/mod.rs b/cli/node/mod.rs index fa6f0bdda..60b46a445 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -492,7 +492,10 @@ pub fn node_resolve( let path = url.to_file_path().unwrap(); // todo(16370): the module kind is not correct here. I think we need // typescript to tell us if the referrer is esm or cjs - let path = path_to_declaration_path(path, NodeModuleKind::Esm); + let path = match path_to_declaration_path(path, NodeModuleKind::Esm) { + Some(path) => path, + None => return Ok(None), + }; ModuleSpecifier::from_file_path(path).unwrap() } }; @@ -532,7 +535,10 @@ pub fn node_resolve_npm_reference( let resolved_path = match mode { NodeResolutionMode::Execution => resolved_path, NodeResolutionMode::Types => { - path_to_declaration_path(resolved_path, node_module_kind) + match path_to_declaration_path(resolved_path, node_module_kind) { + Some(path) => path, + None => return Ok(None), + } } }; let url = ModuleSpecifier::from_file_path(resolved_path).unwrap(); @@ -794,7 +800,9 @@ fn module_resolve( // should use the value provided by typescript instead let declaration_path = path_to_declaration_path(file_path, NodeModuleKind::Esm); - Some(ModuleSpecifier::from_file_path(declaration_path).unwrap()) + declaration_path.map(|declaration_path| { + ModuleSpecifier::from_file_path(declaration_path).unwrap() + }) } else { Some(resolved_specifier) } -- cgit v1.2.3