skip to Main Content

I’ve been trying to build my docker container using the docker-compose up --build command, but every time, I get a whole bunch of errors. I see a lot of node-sass and node-gyp, I’ve googled every combination of the errors, but can’t find a solution.

System

  • MacOS 11.2.3 (MacBook Pro M1)
  • Node 15.0.0
  • Docker 3.3.1

Command Run

  • docker-compose up --build

Dockerfile

FROM node

# Set up client
WORKDIR /usr/src/app/client
COPY ./client/package*.json ./
RUN npm install

COPY ./client/src ./src
COPY ./client/tsconfig.json ./tsconfig.json
COPY ./client/babel.config.js ./babel.config.js
COPY ./client/.eslintrc.json ./.eslintrc.json

RUN npm run build

# Set up server
WORKDIR /usr/src/app/server
COPY ./server/package*.json ./
RUN npm install

COPY ./server/src ./src
COPY ./server/database ./database
COPY ./server/tests ./tests
COPY ./server/tsconfig.json ./tsconfig.json
COPY ./server/knexfile.ts ./knexfile.ts

EXPOSE 3000
CMD ["npm","run","dev"]

docker-compose.yml

version: "3.9"
services:
  app:
    build: .
    ports:
      - "3000:3000"
      - "9229:9229"
    environment:
      NODE_ENV: development
      SESSION_SECRET: a_secret
      REDIS_SECRET: a_secret
      JWT_SECRET: a_secret
      DB_USER: a_user
      DB_PASSWORD: a_password
      DB_NAME: a_database
      DB_HOST: db
      DB_CLIENT: pg
    env_file:
      - ./server/.env
      - ./client/.env
    volumes:
      - ./client/dist:/usr/src/app/client/dist
      - ./server/src:/usr/src/app/server/src
      - ./server/database:/usr/src/app/server/database
      - ./server/tests:/usr/src/app/server/tests
  db:
    image: "postgres"
    restart: always
    environment:
      POSTGRES_USER: a_user
      POSTGRES_PASSWORD: a_password
      POSTGRES_DB: a_redis
    ports:
      - "5432:5432"
  redis:
    image: "redis:alpine"
    command: redis-server --requirepass some_pass
    volumes:
      - ./server/redis.conf:/usr/local/etc/redis/redis.conf
    environment:
      REDIS_REPLICATION_MODE: master

Partial Output of Error (I’d post it all but, it’s quite long)

% docker-compose up --build      
Docker Compose is now in the Docker CLI, try `docker compose up`

Building app
[+] Building 89.5s (8/21)                                                                                                                                                                                   
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 91B                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/node:latest                                                                                                                                         0.0s
 => [internal] load build context                                                                                                                                                                      0.0s
 => => transferring context: 15.26kB                                                                                                                                                                   0.0s
 => [ 1/17] FROM docker.io/library/node                                                                                                                                                                0.0s
 => CACHED [ 2/17] WORKDIR /usr/src/app/client                                                                                                                                                         0.0s
 => CACHED [ 3/17] COPY ./client/package*.json ./                                                                                                                                                      0.0s
 => ERROR [ 4/17] RUN npm install                                                                                                                                                                     89.4s
------                                                                                                                                                                                                      
 > [ 4/17] RUN npm install:                                                                                                                                                                                 
#8 33.75 npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.                                                                          
#8 34.31 npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated                                                                                                               
#8 34.41 npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated                                                                                                            
#8 34.91 npm WARN deprecated [email protected]: this library is no longer supported                                                                                                                       
#8 38.60 npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
#8 38.62 npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
#8 39.38 npm WARN deprecated @hapi/[email protected]: Moved to 'npm install @sideway/address'
#8 39.43 npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
#8 39.88 npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
#8 39.90 npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
#8 40.29 npm WARN deprecated [email protected]: This loader has been deprecated. Please use eslint-webpack-plugin
#8 40.65 npm WARN deprecated [email protected]: 3.x is no longer supported
#8 41.26 npm WARN deprecated @hapi/[email protected]: Switch to 'npm install joi'
#8 42.21 npm WARN deprecated [email protected]: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
#8 89.28 npm notice 
#8 89.28 npm notice New minor version of npm available! 7.10.0 -> 7.11.2
#8 89.28 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.11.2>
#8 89.28 npm notice Run `npm install -g [email protected]` to update!
#8 89.28 npm notice 
#8 89.28 npm ERR! code 1
#8 89.28 npm ERR! path /usr/src/app/client/node_modules/node-sass
#8 89.28 npm ERR! command failed
#8 89.28 npm ERR! command sh -c node scripts/build.js
#8 89.28 npm ERR! Building: /usr/local/bin/node /usr/src/app/client/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
#8 89.28 npm ERR! make: Entering directory '/usr/src/app/client/node_modules/node-sass/build'

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution to my own problem.

    Turns out node-sass is not compatible with node version 16.0.0+

    I realized that in my Dockerfile, I had not specified the node version, I had incorrectly assumed it was using node version 15.0.0, but in reality it was installing node version 16.0.0

    After updating my docker file to FROM node:15.12.0, everything works perfectly


  2. For whoever facing this issue in the future, use sass instead. To be able to use sass files with node 16+
    https://www.npmjs.com/package/sass

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search