Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): load config util supports absolute paths on windows #22837

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/devkit/src/utils/config-utils.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -70,8 +71,9 @@ async function load(path: string): Promise<any> {
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
Expand Down