javascript - 无法构建 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;"]
解决方案
我注意到你在 docker 上运行它,所以在将你的 react 应用程序目录复制到 docker 容器时你在 docker 上做错了。
您尚未Dockerfile
在此处添加代码
所以我们建议你先修复你的 dockerfile。还要检查您的.dockerignore
文件并调试进入 docker 容器,如果该目录存在与否
所以你的 docker 文件应该和这个类似
COPY . ./
RUN npm run build
推荐阅读
- javascript - React js多个日期选择器实例
- javascript - 为什么我不能在调用超级构造函数的箭头函数中使用“this”?
- python - 如果元素存在于另一个熊猫系列中,则熊猫将值添加到列的有效方法
- c# - System.InvalidCastException - 两种情况只有一种错误
- python - SWIG:在 Python 和 C 之间传递字节
- linux - 如何在 Python 2.7 中生成没有 fork() 的进程?
- xamarin - 可重用的 xamarin 控件给出“无法转换类型为'Xamarin.forms.xaml.elementnode'的对象......”
- laravel - Linux服务器上的Laravel 2文件夹冲突
- nginx - 子域路由的行为与 Nginx 中的域不同
- python - 给出日期最接近给定日期的 DataFrame 行