【问题标题】:Building Angular in Docker throws "environment.prod.ts path in file replacements does not exist"在 Docker 中构建 Angular 会引发“文件替换中的 environment.prod.ts 路径不存在”
【发布时间】:2020-09-15 16:50:00
【问题描述】:

当我尝试构建以下 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"
                }
              ],

【问题讨论】:

    标签: node.js angular docker npm


    【解决方案1】:

    我不得不从 COPY 行中删除 *。 以下 DOCKERFILE 有效:

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

    Dockerfile reference 中提到的不需要 *

    如果是目录,则复制目录的全部内容,包括文件系统元数据。

    【讨论】:

      【解决方案2】:

      如果您使用的是 MAC 或 Linux,这可能与权限有关。我设法通过将我的项目文件夹和父文件夹添加到文件共享列表来解决这个问题。只需转到 Docker -> 首选项 -> 资源 -> 文件共享并确保您的项目文件夹包含在列表中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-02
        • 2019-10-13
        • 2021-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多