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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user