Skip to content

Bug: Initialization error (ENOENT / mkdir) on Windows when running astro dev #75

Description

@matheuscostadesign

Description

Running npm run dev on Windows with the aeo.js Astro integration fails during startup with an ENOENT error.

The issue occurs because the integration uses the .pathname property of Astro URL objects when interacting with the filesystem (e.g. config.publicDir.pathname).

On Windows, .pathname returns a value such as:

/C:/dev-front/ruwts/public

When this value is passed to Node.js filesystem APIs, it is interpreted as a relative path from the current drive root, resulting in an invalid path like:

C:\C:\dev-front\ruwts\public

This causes the initialization to fail.

Error

21:29:41 [ERROR] [aeo-astro] An unhandled error occurred while running the "astro:config:setup" hook

ENOENT: no such file or directory, mkdir 'C:\C:\dev-front\ruwts\public'

Location:
  C:\dev-front\ruwts\node_modules\aeo.js\dist\astro.mjs:1379:13

Stack trace:
  at mkdirSync (node:fs:1377:26)
  at hookFn (file:///C:/dev-front/ruwts/node_modules/astro/dist/integrations/hooks.js:55:21)
  at runHookInternal (file:///C:/dev-front/ruwts/node_modules/astro/dist/integrations/hooks.js:52:11)
  at async createContainer (file:///C:/dev-front/ruwts/node_modules/astro/dist/core/dev/container.js:21:14)

Affected code

astro:config:setup

resolvedConfig = resolveConfig({
  ...options,
  contentDir: options.contentDir || "src/content",
  outDir:
    options.outDir ||
    (command === "build"
      ? config.outDir.pathname
      : config.publicDir.pathname)
});

if (command === "dev") {
  const publicPath = config.publicDir.pathname;

  if (!existsSync(publicPath)) {
    mkdirSync(publicPath, { recursive: true });
  }
}

astro:build:done

const outPath =
  dir instanceof URL
    ? dir.pathname
    : dir || astroConfig.outDir.pathname;

Expected behavior

The integration should correctly resolve filesystem paths on all supported platforms (Windows, macOS, and Linux).

Suggested fix

Instead of using .pathname directly, convert file:// URLs into native filesystem paths using Node.js' fileURLToPath() utility.

import { fileURLToPath } from "node:url";

// astro:config:setup
resolvedConfig = resolveConfig({
  ...options,
  contentDir: options.contentDir || "src/content",
  outDir:
    options.outDir ||
    (command === "build"
      ? fileURLToPath(config.outDir)
      : fileURLToPath(config.publicDir))
});

const publicPath = fileURLToPath(config.publicDir);

// astro:build:done
const outPath =
  dir instanceof URL
    ? fileURLToPath(dir)
    : dir || fileURLToPath(astroConfig.outDir);

Using fileURLToPath() ensures proper path conversion across Windows, macOS, and Linux and avoids invalid paths such as C:\C:\....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions