Sollosa
Sollosa

Reputation: 431

Docker Angular run-scripts issue

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

Upvotes: 1

Views: 1362

Answers (1)

leopal
leopal

Reputation: 4959

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

Upvotes: 2

Related Questions