-
Notifications
You must be signed in to change notification settings - Fork 222
server.js path resolution breaks on Windows for Workflow CLI #1395
Copy link
Copy link
Open
Description
Environment
- OS: Windows
- Node.js: ESM ("type": "module")
- Invocation: node server.js or via @workflow/cli
- Package:
@workflow/web@4.1.0-beta.39
Problem
server.js passes a raw Windows absolute path to import():
// server.js — current
import { fileURLToPath } from 'node:url'; // pathToFileURL is NOT imported
const { app } = await import(path.join(buildDir, 'server/index.js'));
// ↑ resolves to C:\...\build\server\index.js on WindowsPath: node_modules.pnpm@workflow+cli@4.2.0-beta.67_85976bb19fd0d4dcde5f60b3715e33f2\node_modules@workflow\web\server.js
On Windows, path.join() produces a backslash absolute path (C:...\build\server\index.js). Node.js ESM's import() only accepts relative specifiers, bare specifiers, or file:// URLs. Passing a raw Windows absolute path throws:
[Error] Failed to start server: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
[Error] Failed to start web UI serverSuggested Fix
Import pathToFileURL from node:url and convert the path before passing it to import():
// server.js — fixed
import { fileURLToPath, pathToFileURL } from 'node:url'; // add pathToFileURL
const { app } = await import(pathToFileURL(path.join(buildDir, 'server/index.js')).href);
// ↑ file:///C:/..../build/server/index.js — valid on all platformsOne import change, one call-site change. Fully backwards-compatible — file:// URLs work identically on macOS and Linux.
References
Node.js docs — ESM import() specifiers
Node.js docs — url.pathToFileURL()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels