Search code examples
node.jsreactjsdockernpmcraco

Create React App fails to build inside docker


I am trying to dockerize a react application. It uses craco for building since I am using tailwindcss. It was working properly until today when the build started throwing errors for CSS files.

The error

 > [admin-build 7/7] RUN npm run build:
#15 1.594 
#15 1.594 > [email protected] build /app
#15 1.594 > craco build
#15 1.594 
#15 3.555 craco:  *** Cannot find ESLint loader (eslint-loader). ***
#15 3.873 Creating an optimized production build...
#15 89.72 Failed to compile.
#15 89.72 
#15 89.72 ./src/styles/index.css
#15 89.72 TypeError: Cannot convert undefined or null to object
#15 89.72     at Function.entries (<anonymous>)
#15 89.72     at Array.forEach (<anonymous>)
#15 89.72 
#15 89.72 
#15 89.75 npm ERR! code ELIFECYCLE
#15 89.75 npm ERR! errno 1
#15 89.76 npm ERR! [email protected] build: `craco build`
#15 89.76 npm ERR! Exit status 1
#15 89.76 npm ERR! 
#15 89.76 npm ERR! Failed at the [email protected] build script.
#15 89.76 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#15 89.76 
#15 89.76 npm ERR! A complete log of this run can be found in:
#15 89.76 npm ERR!     /root/.npm/_logs/2021-06-26T14_32_59_262Z-debug.log
------

My Dockerfile

# base image
FROM node:14-alpine as admin-build

# workdir
RUN mkdir /app
WORKDIR /app
# Install dependencies
COPY package.json ./
RUN npm install
#  copy source
COPY . .
# build source
RUN npm run build
# Nginx for serving
FROM nginx:alpine
# copy configs
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=admin-build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

The application builds properly outside docker. Is there any way to fix this or at least see what the problem is?

Thanks


Solution

  • This was an issue with the node version in docker. I was using node 16 and npm version 7 in my local setup and in docker, it was running node-14 and npm 6. This seems to be causing problems with craco.

    After updating the docker file to use node-16:alpine, It worked.