From 82145e7d02a53444df2d6961c34be04c87b62aab Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 17 Apr 2024 16:32:09 +0100 Subject: [PATCH] fix(core): load config util supports absolute paths on windows (#22837) --- packages/devkit/src/utils/config-utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/devkit/src/utils/config-utils.ts b/packages/devkit/src/utils/config-utils.ts index 5f59dd89a1824..a116472c5dae1 100644 --- a/packages/devkit/src/utils/config-utils.ts +++ b/packages/devkit/src/utils/config-utils.ts @@ -1,6 +1,7 @@ import { dirname, extname, join } from 'path'; import { existsSync, readdirSync } from 'fs'; import { requireNx } from '../../nx'; +import { pathToFileURL } from 'node:url'; const { workspaceRoot, registerTsProject } = requireNx(); @@ -70,8 +71,9 @@ async function load(path: string): Promise { return require(path); } catch (e: any) { if (e.code === 'ERR_REQUIRE_ESM') { - // If `require` fails to load ESM, try dynamic `import()`. - return await dynamicImport(`${path}?t=${Date.now()}`); + // If `require` fails to load ESM, try dynamic `import()`. ESM requires file url protocol for handling absolute paths. + const pathAsFileUrl = pathToFileURL(path).pathname; + return await dynamicImport(`${pathAsFileUrl}?t=${Date.now()}`); } // Re-throw all other errors