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

GitHub Actions部署Node.js到Azure时构建报错:目录不存在

部署Node.js到Azure Web App时的路径大小写问题解决

问题场景

  • 部署目标:Node.js应用至Azure Web App实例
  • Azure实例配置:
    • 操作系统:Linux
    • 运行时栈:Node-20-LTS
  • 本地代码结构:包含tictactoe文件夹(内含package.json)
  • 部署方式:通过GitHub Actions工作流main_tictactoebharat.yml执行部署
  • 构建步骤报错:

Run npm install Error: An error occurred trying to start process '/usr/bin/bash' with working directory '/home/runner/work/rasik210/rasik210/tictactoe'. No such file or directory

工作流文件内容

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js app to Azure Web App - tictactoebharat

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read #This is required for actions/checkout

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'

      - name: npm install, build, and test
        run: |
          npm install
          npm run build --if-present
          npm run test --if-present
        working-directory: tictactoe

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write #This is required for requesting the JWT
      contents: read #This is required for actions/checkout

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: node-app

      - name: Unzip artifact for deployment
        run: unzip release.zip
      
      - name: Login to Azure
        uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_2121E0E0CB924E5C844E27BC59D442D1 }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_BF9CF6B33E584B7E8CE618857E35D3E6 }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_3605AC80CF28413D8D39C856EDB7158E }}

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'tictactoebharat'
          slot-name: 'Production'
          package: .

问题原因与修复方案

问题根源

GitHub Actions的Linux执行器对文件路径大小写敏感,本地文件夹名为tictactoe,但GitHub仓库中实际文件夹为TicTacToe(大驼峰命名),导致工作流中指定的working-directory: tictactoe无法找到对应路径,触发报错。

修复方案

有两种可选方式:

  1. 修改工作流文件中的路径配置,将working-directory的值改为仓库中实际的文件夹名称:
- name: npm install, build, and test
  run: |
    npm install
    npm run build --if-present
    npm run test --if-present
  working-directory: TicTacToe
  1. 统一本地与GitHub仓库的文件夹名称大小写,确保两边完全一致,避免后续再次出现类似问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 01:27:19