Skip to content

Angular fails to build inside docker when target directory for dist does not exist #21208

Closed
@rongem

Description

@rongem

Bug Report

Affected Package

Angular compiler(?)

Is this a regression?

Yes, it worked in 12.0.x. Doesn't work in 12.1.0.

Description

When running ng build --configuration production inside a docker image, and the target dist directory does not exist, build fails with the following error (before compiling ES2015 to ESM2015 messages appear):
angular/angular#15 31.41 An unhandled exception occurred: ENOENT: no such file or directory, stat '/usr/app/dist/project'
angular/angular#15 31.41 See "/tmp/ng-WYeBTH/angular-errors.log" for further details.
Can't get to the log, since the image is thrown away.

  • Error does not occure when running ng build locally on my Windows machine.
  • Error occurs on docker hub and on my local machine's Docker desktop in multiple projects.
  • Error does not occure while building a library, but on every frontend (app).

Minimal Reproduction

Dockerfile

FROM node AS build
WORKDIR /usr/app

COPY ./package*.json ./
RUN npm install
COPY ./ ./
RUN npm run build --configuration production

FROM nginx
WORKDIR /usr/app
COPY --from=build /usr/app/dist/project/ /usr/share/nginx/html/
COPY ./nginx/angular.conf /etc/nginx/conf.d/default.conf

Reproducing with (nearly minimal) repo:
https://github.com/rongem/spi/

Exception or Error



An unhandled exception occurred: ENOENT: no such file or directory, stat '/usr/app/dist/project'

Your Environment

Angular Version:



Angular CLI: 12.1.0
Node: 14.16.0
Package Manager: npm 7.19.0
OS: win32 x64

Angular: 12.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1201.0
@angular-devkit/build-angular   12.1.0
@angular-devkit/core            12.1.0
@angular-devkit/schematics      12.1.0
@schematics/angular             12.1.0
rxjs                            6.6.7
typescript                      4.2.4

Anything else relevant?
Docker version 20.10.7, build f0df350, and also Docker hub autobuild feature
Only Docker related, and libs are not affected

Workaround inside Dockerfile is pasting mkdir between copy and ng build
COPY ./ ./
RUN mkdir dist/project
RUN npm run build:all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions