我的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
它在最后一步退出,并出现以下错误:
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
在这种情况下,是否缺少运行脚本或构建选项?以及如何解决或有什么替代方案?
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"
},
我也尝试过此方法,但均无济于事,抱怨ng未找到
RUN ng build --prod --project edu-app
答案 0 :(得分:2)
“脚本”部分没有build
命令,这就是您获得missing script: build
的原因。
因此将其添加到package.json
:
"scripts": {
"build": "ng build --prod --project edu-app"
}
至此,您正在报告ng
未发现问题,这是正常的,因为@angular/cli
尚未在容器中全局安装。您在这里有两个选择,
npm -i -g @angular/cli
node_modules
内部的路径访问它我建议第一种解决方案,因为它更清楚。
因此,在上面我告诉您的脚本部分中进行了更改之后,您的Dockerfile
应该是:
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