From 6b83e726515bff1489e27a7871bb8442c665ea36 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 26 Apr 2023 14:44:27 +0800 Subject: [PATCH] fix(resolve): deep import resolvedId error --- 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 0d5f4100877dbe..638718a78cd725 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 } }