Skip to content

Commit 31b5f77

Browse files
committed
fix(@angular/cli): normalize Windows drive-letter casing for process.cwd
Windows cmd.exe and VS Code terminals often preserve lowercase drive letters (e.g. c:\...), which causes ESM module duplication in Node.js (e.g. loading 'vitest' twice) and path lookup mismatches in tools like Vite and esbuild. Normalizing process.cwd() early in CLI startup ensures consistent uppercase drive letter casing across all builders, worker threads, and ESM module resolution on Windows.
1 parent b24b444 commit 31b5f77

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

packages/angular/cli/lib/init.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ import { VERSION } from '../src/utilities/version';
2424
let forceExit = false;
2525

2626
(async (): Promise<typeof import('./cli').default | null> => {
27+
/**
28+
* On Windows, ensure process.cwd() uses uppercase drive letter casing.
29+
* Windows cmd.exe and VS Code terminals often preserve lowercase drive letters (e.g. c:\...),
30+
* which causes ESM module duplication in Node.js (e.g. loading "vitest" twice) and path
31+
* lookup mismatches in tools like Vite and esbuild.
32+
*/
33+
if (process.platform === 'win32') {
34+
const cwd = process.cwd();
35+
if (/^[a-z]:/.test(cwd)) {
36+
try {
37+
process.chdir(cwd[0].toUpperCase() + cwd.slice(1));
38+
} catch {
39+
// Ignore failure to change directory
40+
}
41+
}
42+
}
43+
2744
/**
2845
* Disable Browserslist old data warning as otherwise with every release we'd need to update this dependency
2946
* which is cumbersome considering we pin versions and the warning is not user actionable.

0 commit comments

Comments
 (0)