首页 > 解决方案 > 无法构建 React 应用程序 - 管道惨遭失败

问题描述

 ---> Running in 0e34d471598d

> myproject@1.0.0 build /app
> node scripts/build.js

Could not find a required file.
  Name: index.html
  Searched in: /app/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myproject@1.0.0 build: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myproject@1.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/2021-08-05T14_49_57_665Z-debug.log
The command '/bin/sh -c npm run build ;' returned a non-zero code: 1
##[error]The command '/bin/sh -c npm run build ;' returned a non-zero code: 1
##[error]The process '/usr/bin/docker' failed with exit code 1

所以有错误“找不到文件”,但实际上有一个public目录,index.html里面有文件。我不知道为什么会这样……

编辑:我添加了配置管道中使用的 docker 文件

# -- Base node --
FROM node:13.7-alpine AS build

WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
ARG BUILD_ENV
RUN npm run build ;

# -- final build --
FROM nginx:1.17.8-alpine

COPY --from=build /app/build /var/www
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

标签: javascriptreactjsdockerazure-pipelines

解决方案


我注意到你在 docker 上运行它,所以在将你的 react 应用程序目录复制到 docker 容器时你在 docker 上做错了。

您尚未Dockerfile在此处添加代码

所以我们建议你先修复你的 dockerfile。还要检查您的.dockerignore文件并调试进入 docker 容器,如果该目录存在与否

所以你的 docker 文件应该和这个类似

COPY . ./
RUN npm run build

推荐阅读