From 5d1d81ec839bb7070c2b4c78ed2f42bb65ca88b4 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:01:16 +0900 Subject: [PATCH] fix(importAnalysis): backport #13712, strip url base before passing as safeModulePaths --- packages/vite/src/node/plugins/importAnalysis.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index d26b0e219085d9..868207bf2ae2c8 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -478,7 +478,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { const [url, resolvedId] = await normalizeUrl(specifier, start) // record as safe modules - server?.moduleGraph.safeModulesPath.add(fsPathFromUrl(url)) + const urlWithoutBase = + base !== '/' && url.startsWith(base) ? url.replace(base, '/') : url + server?.moduleGraph.safeModulesPath.add(fsPathFromUrl(urlWithoutBase)) if (url !== specifier) { let rewriteDone = false