react-scripts build fails when run through docker

I'm getting compilation errors when I run the react-scripts build command from docker container but it works without problems when I run it locally. The errors seem to be related exclusively to typescript but I'm not 100% sure about that. The errors I'm getting are Syntax error: Unexpected token, expected "," in code that definitely should not have them. Some examples:

#16 63.56 > 11 | type Props<T extends string> = {
#16 63.56      |              ^
#16 70.86    9 | export const ADDRESS_INIT_VALUE = {
#16 70.86 > 10 |        country: (null as unknown) as Country,
#16 70.86      |                       ^

Here is the dockerfile I'm using:

# syntax = docker/dockerfile:experimental

## BUILD image ##
FROM node:15.2.1-alpine3.12 AS builder
WORKDIR /web

# Copy package files
COPY ./web/package.json ./
COPY ./web/yarn.lock ./

# Install dependencies
RUN yarn install

# Copy and build app
COPY ./web ./
RUN yarn build

## RUN Image ##
FROM httpd:alpine

# Apache conf
COPY ./web/.docker/httpd.conf /usr/local/apache2/conf/httpd.conf

COPY --from=builder /web/build/ /usr/local/apache2/htdocs/

So far I've tried multiple node docker images, made no difference. I also made sure I have the exact same version of node and yarn as the docker image. I also deleted node_modules and yarn.lock that I'm using locally and did clean install and build which did not give any errors.

Any suggestions or ideas on why the build is giving these weird errors in docker would be very much appreciated.



Read more here: https://stackoverflow.com/questions/64946165/react-scripts-build-fails-when-run-through-docker

Content Attribution

This content was originally published by Maroš Beťko at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: