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

无法在Azure静态Web应用部署React应用,Oryx构建失败求助

React应用部署Azure Static Web Apps失败排查与解决

问题概述

部署React应用到Azure Static Web Apps时,GitHub Actions执行中出现多个依赖弃用警告,最终Oryx构建失败导致部署终止。

关键日志信息

依赖安装阶段的弃用警告

npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.

added 1654 packages, and audited 1655 packages in 1m

Oryx构建失败提示

---End of Oryx build logs---
Oryx has failed to build the solution.

For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
If you believe this behavior is unexpected, please raise a GitHub issue at https://github.com/azure/static-web-apps/issues/
Exiting

当前Workflow配置

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - sandbox
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - sandbox

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_SEA_000C4D810 }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: "/" # App source code path
          api_location: "" # Api source code path - optional
          output_location: "build" # Built app content directory - optional
          ###### End of Repository/Build Configurations ######

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_SEA_000C4D810 }}
          action: "close"

用户疑问

是否需要从package-lock.json中移除这些被警告的弃用依赖?期望能够正常完成应用部署。

解决步骤

  1. 弃用警告不影响构建:这些npm警告只是提示依赖不再维护,不会直接导致Oryx构建失败,不要直接删除package-lock.json中的依赖,避免破坏项目依赖结构。
  2. 查看完整构建日志:当前日志只显示了失败结果,需要找到---End of Oryx build logs---之前的详细错误信息,比如编译错误、资源路径错误、Node版本不匹配等,这才是失败的核心原因。
  3. 指定Node.js版本:Azure默认使用的Node版本可能和本地不一致,导致构建失败。可以在项目根目录创建.nvmrc文件写入指定版本(如18.17.0),或者在Workflow中添加步骤:
    - name: 配置Node.js版本
      uses: actions/setup-node@v3
      with:
        node-version: '18'
        cache: 'npm'
    
  4. 清理依赖缓存:在Workflow中添加清理缓存的步骤,避免旧依赖干扰:
    - name: 清理并重新安装依赖
      run: npm clean-install
    
  5. 验证构建输出路径:确认package.json中的build命令确实将产物输出到output_location设置的build目录,路径必须完全匹配。
  6. 升级部署Action版本:当前使用的Azure/static-web-apps-deploy@v1版本较旧,建议升级到最新稳定版,修复已知的兼容性问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 21:15:31