diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 41769a995276c2..bf74811cd3de73 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -12,7 +12,7 @@ import { parseAst } from 'rollup/parseAst' import type { StaticImport } from 'mlly' import { ESM_STATIC_IMPORT_RE, parseStaticImport } from 'mlly' import { makeLegalIdentifier } from '@rollup/pluginutils' -import type { PartialResolvedId } from 'rollup' +import type { PartialResolvedId, RollupError } from 'rollup' import type { Identifier, Literal } from 'estree' import { CLIENT_DIR, @@ -348,7 +348,12 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } } - const resolved = await this.resolve(url, importerFile) + const resolved = await this.resolve(url, importerFile).catch((e) => { + if (e instanceof Error) { + ;(e as RollupError).pos ??= pos + } + throw e + }) if (!resolved || resolved.meta?.['vite:alias']?.noResolved) { // in ssr, we should let node handle the missing modules