diff --git a/openrewrite/src/core/tree.ts b/openrewrite/src/core/tree.ts
index 76ebfb4a..35e5de68 100644
--- a/openrewrite/src/core/tree.ts
+++ b/openrewrite/src/core/tree.ts
@@ -530,7 +530,7 @@ export class ParseError implements SourceFile {
return new ParseError(
randomId(),
new Markers(randomId(), [ParseExceptionResult.build(parser, exception)]),
- relativeTo ? path.resolve(input.path, relativeTo) : input.path,
+ relativeTo ? path.relative(relativeTo, input.path) : input.path,
input.fileAttributes,
parser.getCharset(ctx),
false,
@@ -761,4 +761,4 @@ class ParseErrorPrinter
extends ParseErrorVisitor> {
}
return e;
}
-}
\ No newline at end of file
+}
diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts
index 2305480d..8862a4b8 100644
--- a/openrewrite/src/javascript/parser.ts
+++ b/openrewrite/src/javascript/parser.ts
@@ -25,6 +25,7 @@ import {
} from "../core";
import {binarySearch, compareTextSpans, getNextSibling, getPreviousSibling, TextSpan} from "./parserUtils";
import {JavaScriptTypeMapping} from "./typeMapping";
+import path from "node:path";
export class JavaScriptParser extends Parser {
@@ -56,7 +57,7 @@ export class JavaScriptParser extends Parser {
const input = new ParserInput(filePath, null, false, () => Buffer.from(ts.sys.readFile(filePath)!));
try {
const parsed = new JavaScriptParserVisitor(this, sourceFile, typeChecker).visit(sourceFile) as SourceFile;
- result.push(parsed);
+ result.push(parsed.withSourcePath(relativeTo != null ? path.relative(relativeTo, input.path) : input.path));
} catch (error) {
result.push(ParseError.build(this, input, relativeTo, ctx, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error), null));
}