Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): `ENOENT: no such file or director…
Browse files Browse the repository at this point in the history
…y` 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

(cherry picked from commit f844e98)
  • Loading branch information
alan-agius4 committed Jan 22, 2024
1 parent ed95a92 commit 88de1da
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,21 @@ export class ComponentStylesheetBundler {
for (const outputFile of result.outputFiles) {
const filename = path.basename(outputFile.path);

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

if (outputFile.type === BuildOutputFileType.Media) {
// The output files could also contain resources (images/fonts/etc.) that were referenced
outputFiles.push(outputFile);
// Clone the output file to avoid amending the original path which would causes problems during rebuild.
const clonedOutputFile = outputFile.clone();

// Needed for Bazel as otherwise the files will not be written in the correct place,
// this is because esbuild will resolve the output file from the outdir which is currently set to `workspaceRoot` twice,
// once in the stylesheet and the other in the application code bundler.
// Ex: `../../../../../app.component.css.map`.
clonedOutputFile.path = path.join(this.options.workspaceRoot, outputFile.path);

outputFiles.push(clonedOutputFile);
} else if (filename.endsWith('.css')) {
contents = outputFile.text;
} else if (filename.endsWith('.css.map')) {
outputFiles.push(outputFile);
} else {
throw new Error(
`Unexpected non CSS/Media file "${filename}" outputted during component stylesheet processing.`,
Expand Down

0 comments on commit 88de1da

Please sign in to comment.