Skip to content

Windows: Dev server fails with "/@fsC:" import path (vite multi-entry plugin) #7

@Obad94

Description

@Obad94

Steps to reproduce:

  1. Clone repo on Windows (Node 20+, pnpm)
  2. pnpm install
  3. pnpm run dev
  4. Console shows error resolving import /@fsc:/... (missing slash after /@fs)

Error:

Failed to resolve import "/@fsc:/.../src/pizzaz/index.jsx"

Root cause:
Helper toFs in vite.config.mts used "/@fs" (no trailing slash), emitting /@fsc:/... on Windows. path.posix.relative was also not Windows-aware.
i,e:

const toFs = (abs: string) => "/@fs" + abs.replace(/\\/g, "/");

const toServerRoot = (abs: string) =>
  "./" + path.posix.relative(process.cwd(), abs).replace(/\\/g, "/");

Fix:
Use "/@fs/" and platform-aware path.relative with a fallback to /@fs for non-relative cases.
i.e:

const toFs = (abs: string) => "/@fs/" + abs.replace(/\\/g, "/");

const toServerRoot = (abs: string) => {
  const rel = path.relative(process.cwd(), abs).replace(/\\/g, "/");
  // If it's not really relative (different drive or absolute), fall back to fs URL
  if (!rel || rel.startsWith("..") || path.isAbsolute(rel)) return toFs(abs);
  return "./" + rel;
};

Validated:

  • Windows 11: dev server loads all endpoints (HMR works)
  • Linux (Ubuntu): unchanged

No other files changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions