React Deployment to Firebase from Gitlab fails with error: to Specified public directory 'build' does not exist, can't deploy hosting to site

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 文件

{
  "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!"

这是错误:

我尝试了“构建”、“/构建”、“/构建/”、“/PROJECT_NAME/build”,但没有任何效果。我也不知道如何 $ echo 构建路径,以便我可以在项目中调试它。在 Angular 中,“dist”没有任何问题。有什么想法吗?

根据评论部分的对话,部署步骤中似乎没有创建 build 文件夹。它们很可能 运行 在不同的容器中。因此 firebase deploy 命令找不到必要的 build 一个。

我会尝试从 .gitlab-ci.yml 中删除 before_script 并将其步骤与 script 合并为:

  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 文件夹。