我的 Dockerfile
对于 Angular 应用程序
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 Not Found
RUN ng build --prod --project edu-app
最佳答案
没有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
关于angular - Docker Angular运行脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56289486/