new URL(...).pathname of a file: URL is '/D:/a/...' on Windows, so bun and node cannot open the script you just resolved
env paths · case
Symptom
Section titled “Symptom”A test that spawns a sibling CLI script exits 1 on Windows only, and the assertion that catches it says nothing useful:
(fail) dev version bump rule > the CLI rewrites only the version lineerror: expect(received).toBe(expected)Expected: 0Received: 1Worse, the case that expected a nonzero exit for malformed input stayed green: it read the load failure as a correct rejection. Three real cases red, one false green, no message.
const CLI = new URL("../scripts/tool.ts", import.meta.url).pathname;console.log(CLI);Bun.spawnSync(["bun", CLI]).exitCode; // 1 on WindowsPS> bun test x.test.ts/D:/a/repo/scripts/tool.tsnode behaves the same: error: Cannot find module '/D:/a/repo/scripts/tool.ts'.
A file: URL on Windows is file:///D:/a/repo/scripts/tool.ts. The URL’s pathname is
everything after the authority, so it starts with a slash and the drive letter is just the
first path segment: /D:/a/repo/.... That is a valid URL path and an invalid Windows path.
On POSIX the two representations coincide, which is why the shortcut survives every other
platform.
import.meta.url, import.meta.resolve, and new URL(specifier, base) all produce URLs;
they are not paths. Only fileURLToPath performs the conversion, and it also decodes
percent-escapes (%20) that pathname would leave in place.
Workaround
Section titled “Workaround”import { fileURLToPath } from "node:url";const CLI = fileURLToPath(new URL("../scripts/tool.ts", import.meta.url));Bun.spawnSync([process.execPath, CLI, ...args]);Two habits close the false-green gap too: include the child’s stderr in the assertion message so an exit code comes with its reason, and assert the specific rejection text in negative cases rather than “any nonzero exit”.
Sibling cases: file-url-encodes-backslash (the reverse conversion), esm-is-main-file-url
and dynamic-import-needs-file-url (where a path must become a URL).
Repeated occurrence: quota-reset child probes
Section titled “Repeated occurrence: quota-reset child probes”OpenCodex’s post-merge Windows run 33941712300 repeated this in two new tests:
quota-reset-seen-store.test.ts generated a dynamic import from .pathname
(empty stdout, expected true), while quota-reset-observation.test.ts passed
.pathname as the child script argument (exit 1). Neither assertion exposed
the child’s stderr. The final passing Windows verification is separate from
that baseline; PR #3610 carries the correction and its verification status.
The two consumers require different representations: preserve new URL(...).href
for import(), but use fileURLToPath for the spawn script argument. Do not
repair both by stripping the leading slash or by turning the import URL into a
drive-prefixed specifier. Use process.execPath and consume stdout, stderr, and
the exit promise together; assert exit zero before interpreting stdout.