Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly resolve hmr dep ids and fallback to url #18840

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
no fallback
Co-authored-by: 翠 / green <green@sapphi.red>
  • Loading branch information
patricklx and sapphi-red authored Dec 11, 2024
commit be05e5bc02753e8c1cd59ec1991c2110c2f34a27
28 changes: 23 additions & 5 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,29 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
const resolved = await this.resolve(url, importer)
if (resolved?.id) {
const mod = moduleGraph.getModuleById(resolved.id)
normalized = mod?.url
}
if (!normalized) {
const [resolved] = await moduleGraph.resolveUrl(toAbsoluteUrl(url))
normalized = resolved
if (!mod) {
this.error(
`module was not found for ${JSON.stringify(resolved.id)}`,
start,
)
return
}
normalized = mod.url
} else {
try {
const [resolved] = await moduleGraph.resolveUrl(toAbsoluteUrl(url))
if (resolved) {
this.warn({
message:
`Failed to resolve ${JSON.stringify(url)} from ${importer}.` +
' An id should be written. Did you pass a URL?',
pos: start,
})
continue
}
} catch {}
this.error(`Failed to resolve ${JSON.stringify(url)}`, start)
return
}
normalizedAcceptedUrls.add(normalized)
const hmrAccept = normalizeHmrUrl(normalized)
Expand Down
Loading