Skip to content

Commit

Permalink
fix(core): load config util supports absolute paths on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Apr 16, 2024
1 parent 2ee9650 commit 1d725f7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 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 'url';

const { workspaceRoot, registerTsProject } = requireNx();

Expand Down Expand Up @@ -71,7 +72,15 @@ async function load(path: string): Promise<any> {
} 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()}`);
try {
return await dynamicImport(`${path}?t=${Date.now()}`);
} catch (e) {
if (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME') {
const fileUrlPath = pathToFileURL(path).pathname;
return await dynamicImport(`${fileUrlPath}?t=${Date.now()}`);
}
throw e;
}
}

// Re-throw all other errors
Expand Down

0 comments on commit 1d725f7

Please sign in to comment.