diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 31d0e107eb41..9dea3dba55cf 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -2,7 +2,7 @@ import type { AstroConfig } from '../@types/astro-core'; import type { ErrorPayload } from 'vite'; import fs from 'fs'; import path from 'path'; -import { fileURLToPath } from 'url'; +import { fileURLToPath, pathToFileURL } from 'url'; import resolve from 'resolve'; /** Normalize URL to its canonical form */ @@ -76,7 +76,9 @@ export function codeFrame(src: string, loc: ErrorPayload['err']['loc']): string } export function resolveDependency(dep: string, astroConfig: AstroConfig) { - return resolve.sync(dep, { + const resolved = resolve.sync(dep, { basedir: fileURLToPath(astroConfig.projectRoot) }); -} \ No newline at end of file + // For Windows compat, we need a fully resolved `file://` URL string + return pathToFileURL(resolved).toString(); +}