1

My Dockerfile for Angular App

FROM node:10.15.3-alpine as builder

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN apk add git
COPY package*.json /usr/src/app/
RUN npm i

COPY . /usr/src/app

RUN npm run-script build

It exits on last step with the following error:

npm ERR! missing script: build

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-05-24T09_05_54_385Z-debug.log

Is run-script missing or build option in this case? and how to fix or what's the alternative??

script-section of package.json

"scripts": {
    "ng": "ng",
    "edu-start": "ng serve --project edu-app",
    "edu-start-with-api": "ng serve --project edu-app --configuration local_api",
    "edu-start-with-nodejs": "ng serve --project edu-app --configuration local_nodejs",
    "edu-build-dev": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --project edu-app --configuration hmr",
    "edu-build-prod": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --project edu-app --configuration production --prod",
    "air-pilot-start": "ng serve --project air-pilot-app",
    "air-pilot-build-dev": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --project air-pilot-app --configuration hmr",
    "air-pilot-build-prod": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --project air-pilot-app --configuration production --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "bundle-report": "webpack-bundle-analyzer dist/stats.json"
  },

I tried this too instead, but neither worked, complains that ng Not Found

RUN ng build --prod --project edu-app
5
  • 1
    Please post scripts section of your package.json. Commented May 24, 2019 at 9:21
  • make sure you are running the script on the same place as of the package.json Commented May 24, 2019 at 9:29
  • @PranavRamachandran ofc its set in Dockerfile: WORKDIR /usr/src/app Commented May 24, 2019 at 9:33
  • @Pranav ok friend, how to fix? my dev suggests to use ng tho... Commented May 24, 2019 at 9:40
  • run this before your ng build command, npm install -g @angular/cli Commented May 24, 2019 at 9:42

1 Answer 1

2

There is no build command at scripts section, that's the reason you are getting missing script: build.

So add this to package.json:

    "scripts": {
       "build": "ng build --prod --project edu-app"
      }

As for this and ng not found issue you are reporting, it is normal to happen as @angular/cli has not been installed globally in the container. You have two options here,

  • either install it globally npm -i -g @angular/cli
  • or access it directly through its path inside node_modules

I recommend the first solution as it is clearer.

So after making the change in the scripts section I told you above, your Dockerfile should be:

FROM node:10.15.3-alpine as builder

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN apk add git
COPY package*.json /usr/src/app/
RUN npm i

COPY . /usr/src/app

RUN npm -i -g @angular/cli && npm run-script build
Sign up to request clarification or add additional context in comments.

2 Comments

I added the same line in package.json: but I get this error instead: \n npm ERR! JSON.parse Failed to parse package.json data. npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
You have invalid syntax in package.json. You may use an online json validator or use an appropriate IDE which supports error highlighting. Don't forget to put a comma after each entry in scripts section(except last one) of package.json

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.