skip to Main Content

I’m trying to build a docker image for my project with angular and nginx, but I get the following errors at the build phase when trying to mount the image (install seems to work fine):

#11 103.1 Error: src/app/models/index.ts:5:28 - error TS2307: Cannot find module './inputField' or its corresponding type declarations.
#11 103.1
#11 103.1 5 export { InputField } from './inputField';
#11 103.1                              ~~~~~~~~~~~~~~
#11 103.1
#11 103.1
#11 103.1
#11 103.1 npm ERR! code ELIFECYCLE
#11 103.1 npm ERR! errno 1
#11 103.2 npm ERR! [email protected] build: `ng build --build-optimizer --output-hashing=none`
#11 103.2 npm ERR! Exit status 1
#11 103.2 npm ERR!
#11 103.2 npm ERR! Failed at the [email protected] build script.
#11 103.2 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#11 103.2
#11 103.2 npm ERR! A complete log of this run can be found in:
#11 103.2 npm ERR!     /root/.npm/_logs/2021-07-17T10_12_55_066Z-debug.log
------
executor failed running [/bin/sh -c npm run build]: exit code: 1

My dockerfile:

# Angular image
FROM node:latest as build

WORKDIR /app
COPY . .
RUN npm install 
RUN npm run build

# Nginx image
FROM nginx:latest

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

EXPOSE 80

I’ve done npm audit fix to solve a couple issues and I’ve deleted node_modules folder, cache and package-lock.json, and installed again, but none of that seems to help.

Thanks in advance.

2

Answers


  1. Try running ng build command locally before building the docker image. It will show the errors. Currently it can’t access the InputField.

    export { InputField } from './inputField';
    
    Login or Signup to reply.
  2. According to the original issue:

    error TS2307: Cannot find module './inputField'
    

    Renaming a file from InputField.ts to inputField.ts solved the problem with the build inside a container.

    Looking inside Build Container:

    Running only a build container was an excellent comment from @David Maze

    something like this:

    $ docker run --rm -it <name_of_the_container> /bin/bash
    

    this way you can issue a npm run build command and see what is happening inside.

    What I also recommend is to have a clean ng new ngApp as a reference.
    If that app can be built then something else is the problem and not the Dockerfile.

    Sample:

    # Angular build image
    FROM node:latest as builder
    
    WORKDIR /app
    COPY . .
    RUN npm install
    RUN npm run build
    
    
    # Nginx image
    FROM nginx:latest
    
    COPY --from=builder /app/dist/ngApp /usr/share/nginx/html/
    
    EXPOSE 80
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search