Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Conversation

@noam-sc
Copy link

@noam-sc noam-sc commented Oct 2, 2025

Warning : This is a Copilot PR that I tested and it works. A bit verbose but the core is here

Problem

The integration was failing on Windows with ENOENT errors due to incorrect path handling:

ENOENT: no such file or directory, mkdir 'C:\C:\Users\XXX\Documents\www\astroproject\node_modules\.astro\.mysong-compress'
ENOENT: no such file or directory, scandir 'C:\C:\Users\XXX\Documents\www\astroproject\dist\'

The root cause was improper handling of file URLs on Windows. When Astro passes configuration URLs like file:///C:/Users/..., the URL.pathname property returns /C:/Users/... (with a leading slash). Using this directly with path.join() created invalid paths like C:\C:\Users\..., doubling the drive letter.

Solution

Implemented proper URL-to-path conversion using Node.js's built-in fileURLToPath() function from the url module. This function correctly handles the conversion on all platforms:

  • Windows: file:///C:/Users/testC:\Users\test
  • Unix/Linux/macOS: file:///home/user/test/home/user/test

Changes

  1. Cache initialization - Fixed path construction when creating the cache directory:

    // Before: Would create C:\C:\Users\... on Windows
    path.join(config.root.pathname, cacheDir)
    
    // After: Correctly handles all platforms
    path.join(fileURLToPath(config.root), cacheDir)
  2. Directory traversal - Fixed path handling in the traverseDirectory function:

    // Before: Would fail with doubled drive letters
    fs.readdirSync(directory.pathname, { withFileTypes: true })
    
    // After: Properly converts URL to file path
    const dirPath = fileURLToPath(directory)
    fs.readdirSync(dirPath, { withFileTypes: true })
  3. Error handling - Added try-catch blocks and checks for broken symlinks to prevent crashes when encountering inaccessible directories.

Testing

  • Tests made by Copilot
  • I tested it myself on my Windows Astro project and it works great

Copilot AI and others added 3 commits October 2, 2025 16:38
Co-authored-by: noam-sc <13904910+noam-sc@users.noreply.github.com>
…3-fa70cd05a61a

Fix Windows path issues with URL pathname handling
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant