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

Nuxt3应用GitHub Actions部署Azure时遇NewtonSoft.Json异常

Nuxt3静态Web应用部署Azure时遇Newtonsoft.Json构建异常

问题现象

  • 本地执行npm run dev可正常构建运行Nuxt3应用,但通过GitHub Actions部署到Azure Static Web Apps时构建失败
  • 基础Nuxt3空白应用部署Azure无问题,整合业务代码后复现异常;相同代码部署到Vercel完全正常,推测为Azure特有问题
  • 构建时抛出.NET生态常见的Newtonsoft.Json.JsonReaderException,异常提示JSON读取器当前项是数组而非对象

异常信息

Build Operation ID: 75d5ecf1017c042b
OS Type           : bullseye
Image Type        : jamstack

Detecting platforms...
Error: Oops... An unexpected error has occurred.
Error: Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at Microsoft.Oryx.Detector.ParserHelper.ParseJsonFile(ISourceRepo sourceRepo, String filePath) in /usr/oryx/src/Detector/ParserHelper.cs:line 86
at Microsoft.Oryx.Detector.Hugo.HugoDetector.IsHugoJsonFile(ISourceRepo sourceRepo, String[] subPaths) in /usr/oryx/src/Detector/Hugo/HugoDetector.cs:line 218
at Microsoft.Oryx.Detector.Hugo.HugoDetector.IsHugoApp(ISourceRepo sourceRepo, String& appDirectory) in /usr/oryx/src/Detector/Hugo/HugoDetector.cs:line 145
at Microsoft.Oryx.Detector.Hugo.HugoDetector.Detect(DetectorContext context) in /usr/oryx/src/Detector/Hugo/HugoDetector.cs:line 49
at Microsoft.Oryx.BuildScriptGenerator.Hugo.HugoPlatform.Detect(RepositoryContext context) in /usr/oryx/src/BuildScriptGenerator/Hugo/HugoPlatform.cs:line 61
at Microsoft.Oryx.BuildScriptGenerator.DefaultPlatformsInformationProvider.GetPlatformsInfo(RepositoryContext context) in /usr/oryx/src/BuildScriptGenerator/DefaultPlatformsInformationProvider.cs:line 53
at Microsoft.Oryx.BuildScriptGenerator.DefaultBuildScriptGenerator.GenerateBashScript(BuildScriptGeneratorContext context, String& script, List`1 checkerMessageSink) in /usr/oryx/src/BuildScriptGenerator/DefaultBuildScriptGenerator.cs:line 75
at Microsoft.Oryx.BuildScriptGeneratorCli.BuildScriptGenerator.TryGenerateScript(String& generatedScript, Exception& exception) in /usr/oryx/src/BuildScriptGeneratorCli/BuildScriptGenerator.cs:line 63
at Microsoft.Oryx.BuildScriptGeneratorCli.BuildCommand.Execute(IServiceProvider serviceProvider, IConsole console) in /usr/oryx/src/BuildScriptGeneratorCli/Commands/BuildCommand.cs:line 278
at Microsoft.Oryx.BuildScriptGeneratorCli.CommandBase.OnExecute(IConsole console) in /usr/oryx/src/BuildScriptGeneratorCli/Commands/CommandBase.cs:line 87

GitHub Actions工作流配置

name: Azure Static Web Apps CI/CD

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

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@v3
        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_ASHY_MUSHROOM_036506E0F }}
          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. ######
          app_location: "/" # App source code path
          api_location: ".output/server" # Api source code path - optional
          output_location: ".output/public" # 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_ASHY_MUSHROOM_036506E0F }}
          action: "close"

问题原因

Azure使用的Oryx构建引擎在自动检测项目平台时,Hugo检测器会扫描项目中的JSON文件(如hugo.json),如果某个JSON文件的根节点是数组而非对象,就会触发JsonReaderException。你的Nuxt3项目中存在被Hugo检测器误识别的JSON文件,导致平台检测流程崩溃。

解决方案

方案1:移除/重命名误识别的JSON文件

检查项目根目录及子目录,找到所有可能被Hugo检测器扫描的JSON文件(尤其是命名为hugo.json的文件),如果不是Hugo配置文件,直接删除或重命名(比如改为data.json)。

方案2:强制指定Node.js平台并跳过自动检测

在GitHub Actions工作流的Build And Deploy步骤中添加环境变量,强制指定使用Node.js平台,并自定义构建命令:

- 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_ASHY_MUSHROOM_036506E0F }}
    repo_token: ${{ secrets.GITHUB_TOKEN }}
    action: "upload"
    app_location: "/"
    api_location: ".output/server"
    output_location: ".output/public"
  env:
    SKIP_PLATFORM_DETECTION: true
    BUILD_COMMAND: "npm run build"

方案3:配置Oryx忽略特定文件

在项目根目录创建oryx.toml文件,添加以下内容,让Oryx跳过Hugo相关检测:

[platforms]
hugo = false

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 19:07:52