Checked other resources
Example Code
The createAgent examples derive their graph PNG output path with new URL(import.meta.url).pathname. This self-contained reproduction exercises the same URL-to-path conversion without calling an LLM:
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
const target = path.join(os.tmpdir(), "langchain-example-path-repro.png");
const currentFilePath = new URL(pathToFileURL(target)).pathname;
console.log({ currentFilePath, resolved: path.resolve(currentFilePath) });
await fs.writeFile(currentFilePath, "png data");
On Windows this prints a URL pathname and then resolves it as a different filesystem path:
{
currentFilePath: '/C:/Users/<user>/AppData/Local/Temp/langchain-example-path-repro.png',
resolved: 'C:\\C:\\Users\\<user>\\AppData\\Local\\Temp\\langchain-example-path-repro.png'
}
Error: ENOENT: no such file or directory, open 'C:\C:\Users\<user>\AppData\Local\Temp\langchain-example-path-repro.png'
Error Message and Stack Trace (if applicable)
ENOENT: no such file or directory, open 'C:\C:\Users\<user>\...\langchain-example-path-repro.png'
Description
Fifteen examples under examples/src/createAgent/ currently use this pattern before calling fs.writeFile:
const currentFilePath = new URL(import.meta.url).pathname;
const outputPath = currentFilePath.replace(/\.ts$/, ".png");
await fs.writeFile(outputPath, await agent.drawMermaidPng());
On POSIX, a file URL's pathname is usually a usable absolute path. On Windows, it starts with /C:/; Node resolves that as C:\C:\..., so the examples fail after the agent run instead of saving their visualization beside the source file. Percent-encoded characters in paths (for example spaces) are also left encoded by .pathname.
Expected: each example saves its graph PNG next to its TypeScript source on every supported Node platform.
Actual: all 15 affected examples fail with ENOENT on Windows when they attempt to write the PNG.
Node already provides the cross-platform conversion used elsewhere in this repository:
import { fileURLToPath } from "node:url";
const currentFilePath = fileURLToPath(import.meta.url);
I found no existing issue or PR for this specific example-path bug. If maintainers agree with the fix direction, I am happy to update the affected examples and run the examples workspace build and formatting checks.
System Info
langchainjs main: 53dbfc2fa033250fe7b711d7c3c8f6e7bfea9216
OS: Microsoft Windows 11 64-bit, build 26200
Node: v24.15.0
pnpm: 11.19.0 (the reproduction itself only uses Node built-ins)
Checked other resources
mainbranch.Example Code
The
createAgentexamples derive their graph PNG output path withnew URL(import.meta.url).pathname. This self-contained reproduction exercises the same URL-to-path conversion without calling an LLM:On Windows this prints a URL pathname and then resolves it as a different filesystem path:
Error Message and Stack Trace (if applicable)
Description
Fifteen examples under
examples/src/createAgent/currently use this pattern before callingfs.writeFile:On POSIX, a file URL's pathname is usually a usable absolute path. On Windows, it starts with
/C:/; Node resolves that asC:\C:\..., so the examples fail after the agent run instead of saving their visualization beside the source file. Percent-encoded characters in paths (for example spaces) are also left encoded by.pathname.Expected: each example saves its graph PNG next to its TypeScript source on every supported Node platform.
Actual: all 15 affected examples fail with
ENOENTon Windows when they attempt to write the PNG.Node already provides the cross-platform conversion used elsewhere in this repository:
I found no existing issue or PR for this specific example-path bug. If maintainers agree with the fix direction, I am happy to update the affected examples and run the examples workspace build and formatting checks.
System Info