Joba
Joba

Reputation: 898

Building Angular in Docker throws "environment.prod.ts path in file replacements does not exist"

The following Dockerfile throws an error when I try to build it. I also tried with a RUN command to install the angular/cli globally and call with another RUN ng build --prod directly, but the same error occurs.

Dockerfile

FROM node:12.17.0-alpine AS build-angular
WORKDIR /src
COPY webui/* webui/
WORKDIR /src/webui
RUN ["npm", "install"]
RUN ["npm", "run", "build"]

Build Error Output

Step 6/6 : RUN ["npm", "run", "build"]
 ---> Running in 0fb33e92b742

> [email protected] build /src/webui
> ng build --prod

An unhandled exception occurred: The /src/webui/src/environments/environment.prod.ts path in file replacements does not exist.
See "/tmp/ng-fiLpfO/angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] build: `ng build --prod`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-28T11_18_53_532Z-debug.log
The command 'npm run build' returned a non-zero code: 1

Excerpt from angular.json

"production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],

Upvotes: 2

Views: 1281

Answers (2)

Hovik Antanisyan
Hovik Antanisyan

Reputation: 999

It might be related to permissions, if you are using MAC or Linux. I managed to solve the issue by adding my project folder and parent folder to File Sharing list. Just go to Docker -> Preferences -> Resources -> File sharing and make sure your project folder is included in the list.

Upvotes: 0

Joba
Joba

Reputation: 898

I had to remove the * from the COPY line. The following DOCKERFILE works:

FROM node:12.17.0-alpine AS build-angular
WORKDIR /src
COPY webui ./
RUN ["npm", "install"]
RUN ["npm", "run", "build"]

The * is not needed as mentioned in the Dockerfile reference

If is a directory, the entire contents of the directory are copied, including filesystem metadata.

Upvotes: 1

Related Questions