From 30a41ffbeb583311ec227e53c0cd2331d26993b0 Mon Sep 17 00:00:00 2001
From: btea <2356281422@qq.com>
Date: Wed, 26 Apr 2023 21:53:05 +0800
Subject: [PATCH] fix(resolve): deep import resolvedId error (#13010)

---
 packages/vite/src/node/plugins/resolve.ts | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts
index 8966d4ac6aa043..c5a0876a0963a4 100644
--- a/packages/vite/src/node/plugins/resolve.ts
+++ b/packages/vite/src/node/plugins/resolve.ts
@@ -773,8 +773,15 @@ export function tryNodeResolve(
     }
     let resolvedId = id
     if (deepMatch && !pkg?.data.exports && path.extname(id) !== resolvedExt) {
-      resolvedId = resolved.id.slice(resolved.id.indexOf(id))
-      debug?.(`[processResult] ${colors.cyan(id)} -> ${colors.dim(resolvedId)}`)
+      // id date-fns/locale
+      // resolve.id ...date-fns/esm/locale/index.js
+      const index = resolved.id.indexOf(id)
+      if (index > -1) {
+        resolvedId = resolved.id.slice(index)
+        debug?.(
+          `[processResult] ${colors.cyan(id)} -> ${colors.dim(resolvedId)}`,
+        )
+      }
     }
     return { ...resolved, id: resolvedId, external: true }
   }