从Gitlab到Firebase的React部署失败,并出现错误:到指定的公共目录"build"不存在,无法将主机部署到站点 [英] React Deployment to Firebase from Gitlab fails with error: to Specified public directory 'build' does not exist, can't deploy hosting to site
问题描述
这是firebase.json文件
This is the firebase.json file
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
这是我的 .gitlab-ci.yml
:
image: tragopoulos/firebase:latest
stages:
- build
- test
- deploy
cache:
paths:
- node_modules/
key: "$CI_BUILD_REPO"
build:
stage: build
image: node
script:
- echo "# Start building App"
- npm install
- npm build
- echo "# Build successfully!"
artifacts:
expire_in: 1 hour
paths:
- "/build"
- node_modules/
test:
stage: test
image: node
script:
- echo "# Testing App"
- npm install
- CI=true npm test
- echo "# Test successfully!"
deploy-develop:
stage: deploy
environment: tragopoulos-portfolio-dev
only:
- develop
before_script:
- npm install
- npm build
script:
- echo "# Deploying App"
- firebase use tragopoulos-portfolio --token $FIREBASE_TOKEN
- firebase deploy --only hosting -m "Pipeline $CI_PIPELINE_ID Build $CI_BUILD_ID"
- echo "# Deployed successfully!"
这是错误:
我尝试了"build","/build","/build/","/PROJECT_NAME/build";没有任何工作.我也不知道如何 $ echo
构建路径,因此我可以在项目中对其进行调试.在Angular中,"dist"是指没有任何问题的作品.有什么主意吗?
I tried "build", "/build", "/build/", "/PROJECT_NAME/build" nothing is working. I also don't know how to $ echo
the build path so I can debug it in the project. In Angular the "dist" works without any issue. Any idea?
推荐答案
基于注释部分的讨论,似乎在部署步骤中没有创建 build
文件夹.它们很可能在不同的容器中运行.因此, firebase deploy
命令找不到所需的 build
之一.
Based on the conversation on the comment section, it seems there is no build
folder created in the deployment step. Most probably they are running in different containers. Thus the firebase deploy
command does not find the necessary build
one.
我会尝试从 .gitlab-ci.yml
中删除 before_script
,并将其步骤与 script
合并为:
I would try to remove before_script
from .gitlab-ci.yml
and combine its steps with script
as:
script:
- npm install
- npm build
- echo "# Deploying App"
- firebase use tragopoulos-portfolio --token $FIREBASE_TOKEN
- firebase deploy --only hosting -m "Pipeline $CI_PIPELINE_ID Build $CI_BUILD_ID"
- echo "# Deployed successfully!"
这样,您就可以在部署步骤中放置 build
文件夹.
This way you have the build
folder in place for the deployment step.
这篇关于从Gitlab到Firebase的React部署失败,并出现错误:到指定的公共目录"build"不存在,无法将主机部署到站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!