Convert discovered module paths to file URLs for Windows compatibility

On Windows, require.resolve() returns paths like D:\...\index.cjs.js
which when passed to import() causes ERR_UNSUPPORTED_ESM_URL_SCHEME
because the D: prefix is interpreted as a URL protocol. Use
pathToFileURL() to produce proper file:// URLs.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-15 13:35:12 +01:00
parent 47b50ef3c4
commit 7db7ca5714
@@ -18,6 +18,7 @@ import { targetPaths } from '@backstage/cli-common';
import { PackageRoles } from '@backstage/cli-node';
import fs from 'node:fs';
import { resolve as resolvePath } from 'node:path';
import { pathToFileURL } from 'node:url';
/**
* Scans the target project root's package.json for dependencies that are CLI
@@ -57,7 +58,7 @@ export function discoverCliModules(): string[] {
const depPkg = JSON.parse(fs.readFileSync(depPkgPath, 'utf8'));
if (PackageRoles.getRoleFromPackage(depPkg) === 'cli-module') {
const resolvedPath = require.resolve(depName, { paths: [rootDir] });
modules.push(resolvedPath);
modules.push(pathToFileURL(resolvedPath).href);
}
} catch {
// Skip packages that can't be resolved or read