Skip to content

fix(scripts): use pathToFileURL for ESM entrypoint check on Windows#7

Open
yugao-gaos wants to merge 1 commit into
neilsonnn:mainfrom
yugao-gaos:fix/windows-script-entrypoint
Open

fix(scripts): use pathToFileURL for ESM entrypoint check on Windows#7
yugao-gaos wants to merge 1 commit into
neilsonnn:mainfrom
yugao-gaos:fix/windows-script-entrypoint

Conversation

@yugao-gaos
Copy link
Copy Markdown

Problem

On Windows, all 15 .mjs scripts under .claude/scripts/ exit silently with code 0 without ever running their main().

Root cause: the standard ESM "is this script the entrypoint" check uses

if (import.meta.url === `file://${process.argv[1]}`) { ... }

On Windows:

  • import.meta.url resolves to file:///D:/.../foo.mjs (forward slashes)
  • process.argv[1] resolves to D:\...\foo.mjs (backslashes)
  • The string comparison always fails → main() never runs

Verified by running node .claude/scripts/project/project-state.mjs --world test --stage-input — exit code 0, no output, no directories created. macOS / Linux are unaffected because their paths and file URLs share the same separator.

Fix

Use url.pathToFileURL() to construct the comparison URL with platform-correct encoding:

import { pathToFileURL } from "node:url";

if (import.meta.url === pathToFileURL(process.argv[1]).href) { ... }

pathToFileURL produces file:///D:/.../foo.mjs on Windows and file:///foo/bar.mjs on POSIX, which matches import.meta.url exactly in both cases.

Scope

Applied to every script that uses this pattern (15 total):

  • .claude/scripts/asset-pipeline/*.mjs (7 files)
  • .claude/scripts/fal/run-fal.mjs
  • .claude/scripts/image-edit/generate-edit.mjs
  • .claude/scripts/project/*.mjs (5 files)
  • .claude/scripts/sfx/fal-elevenlabs-sfx.mjs
  • .claude/scripts/world/generate-world.mjs

Each file got two changes:

  1. Added import { pathToFileURL } from "node:url";
  2. Swapped the entrypoint check expression

Total diff: +30 / -15 lines, no behavior change on macOS / Linux.

Test

Re-ran project-state.mjs after the fix on Windows 11 + Node 24.11 — emits the expected JSON state and creates the worlds/<slug>/ tree. Other scripts verified by running the IMAGE-BLAST pipeline end-to-end on Windows: clean plate (Agent(image-blast-plate)), world generation (Agent(image-blast-world)), and 3D mesh generation (Agent(image-blast-3d)) all succeed where they previously no-op'd.

🤖 Generated with Claude Code

The check `import.meta.url === \`file://${process.argv[1]}\`` fails silently
on Windows because import.meta.url uses forward-slash file URLs
(file:///D:/...) while process.argv[1] uses backslash paths (D:\...).
Scripts exit 0 without ever running main().

Swap to `pathToFileURL(process.argv[1]).href` which constructs the matching
file URL regardless of platform. Affects 15 generation/project scripts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant