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

求助:用Bitbucket Pipeline部署Nuxt 3至Azure静态Web应用遇阻

问题:Bitbucket Pipeline部署Nuxt3到Azure静态Web应用时内存超限/构建未启动

我尝试通过Bitbucket将Nuxt 3应用部署至Azure静态Web应用,查阅诸多教程仍无头绪。

当前配置

Bitbucket Pipeline配置

pipelines:
    branches:
        main:
            - step:
                  name: Deploy to test
                  deployment: test
                  script:
                      # https://github.com/Azure/static-web-apps/issues/1325#issuecomment-1833538182
                      - chown -R 165536:165536 $BITBUCKET_CLONE_DIR
                      - pipe: microsoft/azure-static-web-apps-deploy:main
                        variables:
                            APP_LOCATION: "$BITBUCKET_CLONE_DIR/"
                            API_LOCATION: "$BITBUCKET_CLONE_DIR/.output/server"
                            OUTPUT_LOCATION: "$BITBUCKET_CLONE_DIR/.output/public"
                            API_TOKEN: $deployment_token

Nuxt配置

已在nuxt.config.ts中添加:

nitro: {
        preset: "azure"
    },

本地通过nuxi build可正常生成staticwebapp.config.json,但Bitbucket日志显示构建未启动。

遇到的问题

  1. 推送代码后,流程卡在Running 'npm install'...,约58分钟后因docker memory limit exceeded失败(应用规模不大,本地构建正常)。
  2. 若未因内存超限失败,会收到如下提示:
    构建提示

请问如何解决这个部署问题?


解决建议

1. 优化Pipeline内存使用

Bitbucket默认容器内存有限,针对npm install阶段做以下优化:

  • 用npm ci替代npm install,它严格按package-lock.json安装,速度更快且内存占用更低。手动提前执行构建步骤,再交给Azure部署管道:
script:
    - chown -R 165536:165536 $BITBUCKET_CLONE_DIR
    - npm ci
    - nuxi build
    - pipe: microsoft/azure-static-web-apps-deploy:main
      variables:
          APP_LOCATION: "$BITBUCKET_CLONE_DIR/"
          API_LOCATION: "$BITBUCKET_CLONE_DIR/.output/server"
          OUTPUT_LOCATION: "$BITBUCKET_CLONE_DIR/.output/public"
          API_TOKEN: $deployment_token
  • 若仓库计划支持,在Bitbucket Pipeline设置中提升容器内存配额。

2. 修正Azure部署参数

Azure部署管道会默认自动执行构建,和本地构建逻辑冲突,需指定跳过自动构建:
在Azure部署变量中添加SKIP_APP_BUILD: "true"和SKIP_API_BUILD: "true",直接使用已构建好的产物:

pipe: microsoft/azure-static-web-apps-deploy:main
  variables:
      APP_LOCATION: "$BITBUCKET_CLONE_DIR/"
      API_LOCATION: "$BITBUCKET_CLONE_DIR/.output/server"
      OUTPUT_LOCATION: "$BITBUCKET_CLONE_DIR/.output/public"
      API_TOKEN: $deployment_token
      SKIP_APP_BUILD: "true"
      SKIP_API_BUILD: "true"

3. 简化路径配置

用相对路径代替绝对路径,避免容器内路径权限问题:

APP_LOCATION: "."
API_LOCATION: ".output/server"
OUTPUT_LOCATION: ".output/public"

4. 排查依赖缓存问题

本地正常但CI失败,可能是缓存或版本差异:

  • 确保package-lock.json已提交到仓库,npm ci会锁定依赖版本。
  • 在script步骤添加npm cache clean --force,清理CI缓存避免异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 13:20:34