Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm ERR! missing script: start error with Docker

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.

like image 969
mcansado Avatar asked Jul 09 '17 21:07

mcansado


People also ask

How to fix NPM err missing script?

npm ERR! missing script: start Solution: You need to tell npm what to do when you run npm start explicitly by editing package.json. First, identify the main file of your application. Most often it is called index.js, server.js or app.js. When you open package.json in an editor, you can also often find a line like

Why is my NPM start script not working?

$ npm start npm ERR! Missing script: "start" This is because while you have a package.json file in your application, the start script is not defined. For most applications, the start script may look as follows:

Why does NPM say no such file or directory error?

When you don’t have the package.json file in the current working directory, your console will return a no such file or directory error: When your package.json file doesn’t have the start command under the scripts property, then NPM will run node server.js instead.

What is the NPM start command?

The npm start command is used to run the start command written inside your project’s package.json file. When you don’t have the package.json file in the current working directory, your console will return a no such file or directory error: $ npm start npm ERR! enoent ENOENT: no such file or directory, open '/package.json'


1 Answers

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.

like image 84
cactusme Avatar answered Nov 02 '22 06:11

cactusme