Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/')
}
Expand All @@ -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('.')
Expand Down