node.js - 在Docker中构建Angular会抛出 “environment.prod.ts path in file replacements does not exist”

标签 node.js angular docker npm

当我尝试构建以下Dockerfile时,将引发错误。
我也尝试使用RUN命令来全局安装angular / cli并直接用另一个RUN ng build --prod调用,但是会发生相同的错误。

Dockerfile

FROM node:12.17.0-alpine AS build-angular
WORKDIR /src
COPY webui/* webui/
WORKDIR /src/webui
RUN ["npm", "install"]
RUN ["npm", "run", "build"]

构建错误输出

Step 6/6 : RUN ["npm", "run", "build"]
 ---> Running in 0fb33e92b742

> webui@0.0.0 build /src/webui
> ng build --prod

An unhandled exception occurred: The /src/webui/src/environments/environment.prod.ts path in file replacements does not exist.
See "/tmp/ng-fiLpfO/angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! webui@0.0.0 build: `ng build --prod`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the webui@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-28T11_18_53_532Z-debug.log
The command 'npm run build' returned a non-zero code: 1

来自angular.json的摘录
"production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],

最佳答案

我必须从COPY行中删除*。
以下DOCKERFILE起作用:

FROM node:12.17.0-alpine AS build-angular
WORKDIR /src
COPY webui ./
RUN ["npm", "install"]
RUN ["npm", "run", "build"]

Dockerfile reference中所述,不需要*

If is a directory, the entire contents of the directory are copied, including filesystem metadata.

关于node.js - 在Docker中构建Angular会抛出 “environment.prod.ts path in file replacements does not exist”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62063567/

相关文章:

javascript - 构建 Node.js 开发的第一步是什么

javascript - 我需要从 header 中替换 Bearer 以验证 token

javascript - Angular 应用程序中 <object> 标签的安全错误

angular - 如何在我的 Jasmine /Protractor 测试中执行 typescript 样式继承?

angular - 无法在 TypeScript 中为 Map<TKey, TValue[]> 编写扩展方法

docker - docker-compose:将数据库连接共享到多个网站

Node.js TCP 套接字 session

javascript - 逐行读取文件,完成后执行一些操作(NodeJS)

java - 为什么是 !在docker上的spring-boot应用程序的属性文件路径中?

Docker 无法应用检查的共享驱动器