'Docker build for vue project module not found error

I am trying to build a vue app docker image but I keep getting this error

Module not found: Error: Can't resolve './src/main.js' in '/app'

I am using the a multi-stage dockerfile

FROM node:15.4 as build

WORKDIR /app

COPY ./frontend/package.json .

RUN npm install

COPY . .

RUN npm run build


FROM nginx:1.19

COPY ./frontend/nginx/nginx.conf /etc/nginx/nginx.conf

COPY --from=build /app/dist /usr/share/nginx/html

Here's the script section of the package.json file

"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },

This is a detailed log of the build process

[+] Building 26.9s (14/16)                                                                                                               
 => [internal] load build definition from frontend.dockerfile                                                                       0.0s
 => => transferring dockerfile: 293B                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                   0.0s
 => => transferring context: 34B                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/nginx:1.19                                                                       2.5s
 => [internal] load metadata for docker.io/library/node:15.4                                                                        2.4s
 => [auth] library/node:pull token for registry-1.docker.io                                                                         0.0s
 => [auth] library/nginx:pull token for registry-1.docker.io                                                                        0.0s
 => [build 1/6] FROM docker.io/library/node:15.4@sha256:a76eb778d162f8fd96138d9ca7dbd14b8916c201775a97d2f2aa22e9f13eb105            0.0s
 => [stage-1 1/3] FROM docker.io/library/nginx:1.19@sha256:df13abe416e37eb3db4722840dd479b00ba193ac6606e7902331dcea50f4f1f2         0.0s
 => [internal] load build context                                                                                                   8.5s
 => => transferring context: 166.03MB                                                                                               8.4s
 => CACHED [build 2/6] WORKDIR /app                                                                                                 0.0s
 => CACHED [build 3/6] COPY ./frontend/package.json .                                                                               0.0s
 => CACHED [build 4/6] RUN npm install                                                                                              0.0s
 => [build 5/6] COPY . .                                                                                                            7.4s
 => ERROR [build 6/6] RUN npm run build                                                                                             8.3s
------                                                                                                                                   
 > [build 6/6] RUN npm run build:                                                                                                        
#14 2.913 
#14 2.913 > [email protected] build
#14 2.913 > vue-cli-service build
#14 2.913 
#14 4.668 All browser targets in the browserslist configuration have supported ES module.

I move the frontend folder from the project to stand alone and I am able to build the image and run a container based on it successfully. enter image description here

What could possibly be wrong here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source