You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过GitHub Action部署Firebase Functions问题排查

问题:GitHub Action部署Firebase Functions时出现firebase-functions未找到错误

本地部署一切正常,但通过GitHub Action使用Docker容器部署Firebase Functions时,出现spawn ./node_modules/.bin/firebase-functions ENOENT错误。容器内部署流程正常,文件结构无误,node_modules也位于正确目录。疑问:是否需要为Docker配置端口暴露才能让Firebase部署时正确下载依赖?

错误信息

[2022-10-08T08:09:34.513Z] Building nodejs source
i  functions: Loaded environment variables from .env.development. 
[2022-10-08T08:09:34.518Z] Could not find functions.yaml. Must use http discovery
[2022-10-08T08:09:34.533Z] Error: spawn ./node_modules/.bin/firebase-functions ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

action.yml配置

deploy-cloud:
  name: Deploy Cloud
  needs: e2e-test
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: '16'
    - name: Checkout Repo
      uses: actions/checkout@master
    - name: Make envfile
      uses: docker://xxxxxx/create-envfile:master
      with:
        ...env vars...
        directory: functions
        file_name: .env.development
        fail_on_empty: false
    - name: Install Dependencies
      working-directory: functions
      run: yarn
    - name: Build
      working-directory: functions
      run: yarn build
    - name: Deploy to Firebase
      uses: docker://xxxxxx/firebase-action:master
      with:
        args: deploy --project development --only functions --debug
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

部署动作的Dockerfile

FROM node:16.16.0-buster

LABEL version="0.0.1"
LABEL repository="https://github.com/xxxxxx/firebase-action"
LABEL homepage="https://github.com/xxxxxx/firebase-action"
LABEL maintainer="xxxxxx"

LABEL com.github.actions.name="GitHub Action for Firebase"
LABEL com.github.actions.description="Wraps the firebase-tools CLI to enable common commands."
LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="gray-dark"

RUN apt update && apt-get install -y jq openjdk-11-jre

RUN npm i -g npm@8.10.0
RUN npm i -g firebase-tools@11.8.0

COPY LICENSE README.md /
COPY "entrypoint.sh" "/entrypoint.sh"

ENTRYPOINT ["/entrypoint.sh"]
CMD ["--help"]

解决方案

不需要配置端口暴露,该问题与端口无关,核心是容器内环境与本地的一致性问题,以下是具体排查和修复步骤:

  1. 验证依赖安装完整性

    • 在Install Dependencies步骤后添加验证命令,确认firebase-functions是否存在:
      - name: Verify firebase-functions exists
        working-directory: functions
        run: ls -la ./node_modules/.bin/firebase-functions
      
    • 确保firebase-functions在package.json的dependencies字段中(而非devDependencies),Firebase部署时会忽略开发依赖。
  2. 检查Docker容器的工作目录与文件挂载

    • GitHub Action默认将仓库代码挂载到容器的/github/workspace目录,需确认自定义firebase-action的entrypoint.sh是否切换到了functions目录。修改entrypoint.sh,执行firebase命令前添加:
      cd /github/workspace/functions
      
  3. 统一包管理器环境

    • 本地使用yarn安装依赖,但Docker容器仅全局安装了npm,可能导致依赖版本差异。在Dockerfile中添加yarn安装命令:
      RUN npm i -g yarn
      
  4. 替换为官方Firebase Action

    • 官方firebase-tools Action已处理环境一致性问题,比自定义镜像更可靠,可替换当前部署步骤:
      - name: Deploy to Firebase
        uses: firebaseaction/firebaseaction@v1
        with:
          args: deploy --project development --only functions --debug
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
      

内容的提问来源于stack exchange,提问作者Jeff Voss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 00:55:26