0

My Serverless (sls) application fails to build inside a Docker container due to type errors (TS2322) during the webpack build process. When built locally, there are no errors and app runs as designed.

Error Example:

ERROR in /app/src/controllers/account.controller.ts
 ./src/controllers/account.controller.ts
 [tsl] ERROR in /app/src/controllers/account.controller.ts(19,9)
 TS2322: Type 'string' is not assignable to type 'number'.

I think it may have something to do with the WORKDIR of the container being assigned as /app and the webpack.config.js but I am not sure where to start troubleshooting.

Background:

My Serverless app successfully builds locally using the npm script:"export AWS_REGION=us-east-1 && export IS_ON_LOCAL_SERVER=true && export TZ=UTC && sls offline start --stage dev". When I run this script inside a Docker container it results in numerous Type errrors during the webpack build process.

My Dockerfile (below) uses node:10.10 and I install serverless globally. I have tried using node:8.16 as well and I get the same build errors (using 10.10 in a container I get no npm warnings as I get npm warnings using 8.16).

Dockerfile:

# base image
FROM node:10.10

# update
RUN apt-get update && apt-get install -y --no-install-recommends vim && apt-get clean

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# add app
COPY . /app

# install 
COPY package.json /app/package.json
RUN npm install serverless -g && npm i

# start app
CMD npm run local-server

Docker-Compose:

version: '3.7'

services:

  backend:
    container_name: omp_backend
    build:
      context: ./backend
      dockerfile: Dockerfile
    expose:
      - 3001

    volumes:
      - './backend:/app'
      - '/app/node_modules'
    ports:
      - '3001:3001'
cbilliau
  • 987
  • 9
  • 20
  • Does the error occur during the image build, or is it trying to run `tsc` during the container startup? – David Maze Sep 27 '19 at 15:19
  • It happens after the build. I run ```docker-compose up --build```, it builds the container, logs 'Starting omp_backend...done", and then starts logging "Serverless: Bundling with Webpack...". After that I get the build summary with the list of build errors. – cbilliau Sep 27 '19 at 15:37
  • 1
    The `volumes:` are overriding the code in your image with whatever you happen to have on your local machine (and the `node_modules` from an arbitrary older point in time). I'd suggest deleting those, making sure things like compilation happen during the build phase, and trying again. – David Maze Sep 27 '19 at 15:38
  • Thank you. That solved my build problems. It appears to have been the ```volumes: - '/app/node_modules'``` that was causing the build problems. Thank you! – cbilliau Sep 27 '19 at 15:50

0 Answers0