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'