Skip to content

Commit f844e98

Browse files
committed
fix(@angular-devkit/build-angular): ENOENT: no such file or directory on Windows during component rebuild
Previously, we `joined` the workspace root with the `outputFile.path`, in windows this caused a problem as during the 2nd rebuild it caused the workspace root to be prepended again which causes a `ENOENT` error. To avoid this problem, now we `clone` the output file. Closes #26900
1 parent 222c0b2 commit f844e98

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/angular/component-stylesheets.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,21 @@ export class ComponentStylesheetBundler {
126126
for (const outputFile of result.outputFiles) {
127127
const filename = path.basename(outputFile.path);
128128

129-
// Needed for Bazel as otherwise the files will not be written in the correct place.
130-
outputFile.path = path.join(this.options.workspaceRoot, outputFile.path);
129+
if (outputFile.type === BuildOutputFileType.Media || filename.endsWith('.css.map')) {
130+
// The output files could also contain resources (images/fonts/etc.) that were referenced and the map files.
131131

132-
if (outputFile.type === BuildOutputFileType.Media) {
133-
// The output files could also contain resources (images/fonts/etc.) that were referenced
134-
outputFiles.push(outputFile);
132+
// Clone the output file to avoid amending the original path which would causes problems during rebuild.
133+
const clonedOutputFile = outputFile.clone();
134+
135+
// Needed for Bazel as otherwise the files will not be written in the correct place,
136+
// this is because esbuild will resolve the output file from the outdir which is currently set to `workspaceRoot` twice,
137+
// once in the stylesheet and the other in the application code bundler.
138+
// Ex: `../../../../../app.component.css.map`.
139+
clonedOutputFile.path = path.join(this.options.workspaceRoot, outputFile.path);
140+
141+
outputFiles.push(clonedOutputFile);
135142
} else if (filename.endsWith('.css')) {
136143
contents = outputFile.text;
137-
} else if (filename.endsWith('.css.map')) {
138-
outputFiles.push(outputFile);
139144
} else {
140145
throw new Error(
141146
`Unexpected non CSS/Media file "${filename}" outputted during component stylesheet processing.`,

0 commit comments

Comments
 (0)