11

When running docker-compose to launch my app, I'm getting a npm ERR! missing script: start despite having a start script specified.

package.json is

{
  "name": "myapp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.17.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.3",
    "ejs": "~2.5.6",
    "express": "~4.15.2",
    "mongoose": "^4.11.1",
    "morgan": "~1.8.1",
    "serve-favicon": "~2.4.2"
  }
}

and docker-compose.yml is

version: "2"
services:
  web:
    build: .
    volumes:
      - ./:/app
    ports:
      - "3500:3500"

2 things are not making sense to me:

  1. Launching the app with its Dockerfile works: if the missing start script really was the problem, shouldn't this fail as well?
  2. package.json does have a start script as you can see above

Not sure if needed but the Dockerfile is

FROM node:argon

RUN mkdir /app

WORKDIR /app

COPY package.json /app

RUN npm install

COPY . /app

EXPOSE 3500

ENV PORT 3500
CMD ["npm", "start"]

EDIT: I'm using docker run -p 3500:3500 app and docker-compose up

I'm new to this so may be missing something but am a bit stuck now.

3
  • What command are you using to launch without docker compose?
    – kewne
    Commented Jul 9, 2017 at 21:44
  • 1
    have you tried again with docker-compose up --build ?
    – Robert
    Commented Jul 9, 2017 at 21:46
  • I had the same issue and @Robert answer solved it for me. Needed to use --build to get the original Dockerfile dependencies to rebuild the new npm dependencies I had.
    – abe732
    Commented Jul 31, 2017 at 23:16

5 Answers 5

6

You could try removing the volumes section - ./:/app
It looks like the /app is created within the container, but then subsequently you mount a host directory to /app, thus hiding the original /app in the container.

2

Check that there is a package.json file in the same directory as the docker-compose.yml file that defines the "start" script. If not then that is likely the cause of the error as you're mounting the current directory into the container's app directory. A better setup would be to have your node app in it's own sub directory and leave the docker-compose file where it is. Then you could point to your node app directory by providing it to the build entry of your docker-compose.yml file:

version: "2"
services:
  web:
    build: ./yourNodeAppDir
    volumes:
      - ./:/app # is this necessary?
    ports:
      - "3500:3500"
2

I was getting this error and then I realized I was using vite. I had to change the line from

CMD ["npm", "start"]

to

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

More on containerization of react with vite in this blog https://xeon2k.wordpress.com/2024/01/25/containerizing-react-app-with-vite/

1

The error you receive is that you cannot see the ./bin/www directory.

Follow the steps below.

  1. Is there ./bin/www directory.
  2. If there isn't. You must create.
  3. If there is. You must check is it running.

I hope I have been helpful.

1

add

"docker":xxxxx
"docker-build":xxxxx

mines like this

"docker": "node --experimental-modules ./signal-server",
"docker-build": "docker build -t node-web-development/signalauth ."

your package json file

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.