From 4372a1e5f516b0c4fb3991ee455f3b499be5788f Mon Sep 17 00:00:00 2001 From: zhangyu96 Date: Tue, 8 Mar 2022 20:50:58 +0800 Subject: [PATCH] fix: resolve url --- .../vite/src/node/plugins/importAnalysis.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 953304e0ac38c2..386bd3e4e40dcd 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -178,6 +178,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { url: string, pos: number ): Promise<[string, string]> => { + const rawUrl = url if (base !== '/' && url.startsWith(base)) { url = url.replace(base, '/') } @@ -200,16 +201,22 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } } - const resolved = await this.resolve(url, importerFile) + let resolved = await this.resolve(url, importerFile) if (!resolved) { - this.error( - `Failed to resolve import "${url}" from "${path.relative( - process.cwd(), - importerFile - )}". Does the file exist?`, - pos - ) + // #7220 + // fallback to rawUrl + // to aviod rawUrl conflicting with base config + resolved = await this.resolve(rawUrl, importerFile) + if (!resolved) { + this.error( + `Failed to resolve import "${url}" from "${path.relative( + process.cwd(), + importerFile + )}". Does the file exist?`, + pos + ) + } } const isRelative = url.startsWith('.')