diff --git a/packages/ngtools/webpack/src/compiler_host.ts b/packages/ngtools/webpack/src/compiler_host.ts index eaf9c0421c28..302670628b79 100644 --- a/packages/ngtools/webpack/src/compiler_host.ts +++ b/packages/ngtools/webpack/src/compiler_host.ts @@ -359,7 +359,7 @@ export class WebpackCompilerHost implements ts.CompilerHost { } getCanonicalFileName(fileName: string): string { - const path = this.resolve(fileName); + const path = workaroundResolve(this.resolve(fileName)); return this.useCaseSensitiveFileNames() ? path : path.toLowerCase(); } diff --git a/packages/ngtools/webpack/src/utils.ts b/packages/ngtools/webpack/src/utils.ts index db4336ada4b2..e3f4c0796c2b 100644 --- a/packages/ngtools/webpack/src/utils.ts +++ b/packages/ngtools/webpack/src/utils.ts @@ -9,9 +9,11 @@ import { Path, getSystemPath, normalize } from '@angular-devkit/core'; // `TsCompilerAotCompilerTypeCheckHostAdapter` in @angular/compiler-cli seems to resolve module // names directly via `resolveModuleName`, which prevents full Path usage. +// NSTSC also uses Node.JS `path.resolve` which will result in incorrect paths in Windows +// Example: `/D/MyPath/MyProject` -> `D:/d/mypath/myproject` // To work around this we must provide the same path format as TS internally uses in // the SourceFile paths. -export function workaroundResolve(path: Path | string) { +export function workaroundResolve(path: Path | string): string { return forwardSlashPath(getSystemPath(normalize(path))); } @@ -20,6 +22,6 @@ export function flattenArray(value: Array): T[] { } // TS represents paths internally with '/' and expects paths to be in this format. -export function forwardSlashPath(path: string) { +export function forwardSlashPath(path: string): string { return path.replace(/\\/g, '/'); }