From 9f44a513ee3436c0fc055c0fbdbeb8bfff62c329 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 27 Oct 2021 09:11:20 -0700 Subject: [PATCH] [next] Fix `resolveDependency` on Windows (#1666) * fix: Windows issue with resolveDependency util * chore: add comment --- packages/astro/src/core/util.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 31d0e107eb..9dea3dba55 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(); +}