diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 25a2d133d..3df7a769c 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -158,7 +158,10 @@ export function rootRelativePath(root: URL, idOrUrl: URL | string, prependSlash } else { id = idOrUrl; } - id = id.slice(normalizePath(fileURLToPath(root)).length); + const normalizedRoot = normalizePath(fileURLToPath(root)); + if (id.startsWith(normalizedRoot)) { + id = id.slice(normalizedRoot.length); + } return prependSlash ? prependForwardSlash(id) : id; }