(id, importer, { kind })
| 2461 | resolveId: { |
| 2462 | filter: { id: /^[^.#].*/ }, |
| 2463 | handler(id, importer, { kind }) { |
| 2464 | if (!importer || path.isAbsolute(id) || isNodeBuiltin(id)) { |
| 2465 | return |
| 2466 | } |
| 2467 | |
| 2468 | // With the `isNodeBuiltin` check above, this check captures if the builtin is a |
| 2469 | // non-node built-in, which esbuild doesn't know how to handle. In that case, we |
| 2470 | // externalize it so the non-node runtime handles it instead. |
| 2471 | if (isNodeLikeBuiltin(id) || id.startsWith('npm:')) { |
| 2472 | return { id, external: true } |
| 2473 | } |
| 2474 | |
| 2475 | const isImport = isESM || kind === 'dynamic-import' |
| 2476 | let idFsPath: string | undefined |
| 2477 | try { |
| 2478 | idFsPath = nodeResolveWithVite(id, importer, { |
| 2479 | root, |
| 2480 | isRequire: !isImport, |
| 2481 | }) |
| 2482 | } catch (e) { |
| 2483 | if (!isImport) { |
| 2484 | let canResolveWithImport = false |
| 2485 | try { |
| 2486 | canResolveWithImport = !!nodeResolveWithVite(id, importer, { |
| 2487 | root, |
| 2488 | }) |
| 2489 | } catch {} |
| 2490 | if (canResolveWithImport) { |
| 2491 | throw new Error( |
| 2492 | `Failed to resolve ${JSON.stringify( |
| 2493 | id, |
| 2494 | )}. This package is ESM only but it was tried to load by \`require\`. See https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`, |
| 2495 | ) |
| 2496 | } |
| 2497 | } |
| 2498 | throw e |
| 2499 | } |
| 2500 | if (!idFsPath) return |
| 2501 | // always no-externalize json files as rolldown does not support import attributes |
| 2502 | if (idFsPath.endsWith('.json')) { |
| 2503 | return idFsPath |
| 2504 | } |
| 2505 | |
| 2506 | if (idFsPath && isImport) { |
| 2507 | idFsPath = pathToFileURL(idFsPath).href |
| 2508 | } |
| 2509 | return { id: idFsPath, external: true } |
| 2510 | }, |
| 2511 | }, |
| 2512 | }, |
| 2513 | { |
nothing calls this directly
no test coverage detected