diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 121b5e61714171..c8fb7afe640c7f 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -192,6 +192,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, '/') } @@ -214,20 +215,26 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } } - const resolved = await this.resolve(url, importerFile) + let resolved = await this.resolve(url, importerFile) if (!resolved) { // in ssr, we should let node handle the missing modules if (ssr) { return [url, url] } - 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('.')