Angular12 Dockerization esbuild issue

Viewed 697

I am trying to Dockerize my Angular12 app. I am able to Dockerize it fine when building using development as the environment. However, when building as production (production as default build and ng serve environment) I am getting some esbuild error on the npm run build section of the Dockerfile.

Here is the error log (the .... after MZ was some special undecipherable characters originally) :

#15 1.112 > ng build
#15 1.112
#15 4.377 - Generating browser application bundles (phase: setup)...
#15 17.18 /app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/esbuild.exe: 1: /app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/esbuild.exe: MZ....: not found
#15 17.18 /app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/esbuild.exe: 3: /app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/esbuild.exe: Syntax error: end of file unexpected (expecting ")")

Here is the Dockerfile:

FROM node:16.8.0 as build-step
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
RUN npm run build

FROM nginx:1.20.1
COPY --from=build-step /app/dist/my-app /usr/share/nginx/html
EXPOSE 4200:80
1 Answers

If your application folder contains node_modules, try deleting it before starting the Dockerfile build, or exclude it from being copied into the container.

The reason it might fail is that the esbuild binary is environmentally dependent and the one that you use for your local environment may not necessarily work with the docker image.

Source: I had similar issue with building an application locally on my Macbook when it was working fine on my server.

Related