0

I using node:latest image. And get ModuleBuildError: Module build failed: ModuleBuildError: Module build failed: Error: spawn /hobover_web_client/node_modules/pngquant-bin/vendor/pngquant ENOENT.
Dockerfile

FROM node:latest

# set working directory
RUN mkdir -p /hobover_web_client
WORKDIR /hobover_web_client
ENV NPM_CONFIG_LOGLEVEL=warn
COPY package.json yarn.lock /hobover_web_client/

# install app dependencies   
RUN  rm -rf  node_modules/ && yarn install --ignore-scripts && yarn global add babel babel-cli webpack nodemon pngquant optipng recjpeg
ADD . /hobover_web_client

In docker-compose.yml

version: '2'
  hobover_web_client:
    container_name: hobover_web_client
    build: ./hobover_web_client
    command: yarn start    
    ports:
      - "8080:8080"
    volumes:
      - ./hobover_web_client:/hobover_web_client
      - /hobover_web_client/node_modules

Build work successfully, but up cause an error. How can I fix it if without docker it works?

2
  • Before the yarn install, you didn't copy package.json inside the container. Why? Commented Sep 12, 2017 at 8:00
  • Sorry, fixed, have copied from the wrong file, but error still there Commented Sep 12, 2017 at 8:20

1 Answer 1

1

Your issue the is mount of app and node_modules in the same directory. When you use below in docker-compose

  - ./hobover_web_client:/hobover_web_client

You are overshadowing the existing node_modules. So you need to use NODE_PATH to relocate your packages. Change your Dockerfile to below

FROM node:latest

# set working directory
RUN mkdir -p /hobover_web_client /node_modules
WORKDIR /hobover_web_client
ENV NPM_CONFIG_LOGLEVEL=warn NODE_PATH=/node_moudles
COPY package.json yarn.lock /hobover_web_client/

# install app dependencies   
RUN  yarn install --ignore-scripts && yarn global add babel babel-cli webpack nodemon pngquant optipng recjpeg
ADD . /hobover_web_client

Change your compose to below

version: '2'
  hobover_web_client:
    container_name: hobover_web_client
    build: ./hobover_web_client
    command: yarn start    
    ports:
      - "8080:8080"
    volumes:
      - ./hobover_web_client:/hobover_web_client
      - /node_modules

So now your /node_modules goes to a anonymous volume, which you as such don't need and can remove, because the path is inside different folder

Sign up to request clarification or add additional context in comments.

4 Comments

I added your noticed, but, unfortunately, problem left
I had a typo in Dockerfile. Change ENV NPM_CONFIG_LOGLEVEL=warn NODE_PATH=/node_moudles to ENV NPM_CONFIG_LOGLEVEL=warn NODE_PATH=/node_modules
I fixed typo and nothing changed
Post the out of docker-compose logs to your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.