(
url: string,
pos: number,
forceSkipImportAnalysis: boolean = false,
)
| 335 | : null |
| 336 | |
| 337 | const normalizeUrl = async ( |
| 338 | url: string, |
| 339 | pos: number, |
| 340 | forceSkipImportAnalysis: boolean = false, |
| 341 | ): Promise<[string, string | null]> => { |
| 342 | let importerFile = importer |
| 343 | |
| 344 | if ( |
| 345 | depsOptimizer && |
| 346 | moduleListContains(depsOptimizer.options.exclude, url) |
| 347 | ) { |
| 348 | await depsOptimizer.scanProcessing |
| 349 | |
| 350 | // if the dependency encountered in the optimized file was excluded from the optimization |
| 351 | // the dependency needs to be resolved starting from the original source location of the optimized file |
| 352 | // because starting from node_modules/.vite will not find the dependency if it was not hoisted |
| 353 | // (that is, if it is under node_modules directory in the package source of the optimized file) |
| 354 | for (const optimizedModule of depsOptimizer.metadata.depInfoList) { |
| 355 | if (!optimizedModule.src) continue // Ignore chunks |
| 356 | if (optimizedModule.file === importerModule.file) { |
| 357 | importerFile = optimizedModule.src |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | const resolved = await this.resolve(url, importerFile).catch((e) => { |
| 363 | if (e instanceof Error) { |
| 364 | ;(e as RollupError).pos ??= pos |
| 365 | } |
| 366 | throw e |
| 367 | }) |
| 368 | |
| 369 | // NOTE: resolved.meta is undefined in dev |
| 370 | if (!resolved || resolved.meta?.['vite:alias']?.noResolved) { |
| 371 | // in ssr, we should let node handle the missing modules |
| 372 | if (ssr) { |
| 373 | return [url, null] |
| 374 | } |
| 375 | // fix#9534, prevent the importerModuleNode being stopped from propagating updates |
| 376 | importerModule.isSelfAccepting = false |
| 377 | moduleGraph._hasResolveFailedErrorModules.add(importerModule) |
| 378 | return this.error( |
| 379 | `Failed to resolve import "${url}" from "${normalizePath( |
| 380 | path.relative(process.cwd(), importerFile), |
| 381 | )}". Does the file exist?`, |
| 382 | pos, |
| 383 | ) |
| 384 | } |
| 385 | |
| 386 | if (isExternalUrl(resolved.id)) { |
| 387 | return [resolved.id, resolved.id] |
| 388 | } |
| 389 | |
| 390 | url = normalizeResolvedIdToUrl(environment, url, resolved) |
| 391 | |
| 392 | try { |
| 393 | // delay setting `isSelfAccepting` until the file is actually used (#7870) |
| 394 | // We use an internal function to avoid resolving the url again |
no test coverage detected