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

Nuxt集成@sidebase/nuxt-auth部署Azure Web App遇堆内存溢出求助

问题:添加@sidebase/nuxt-auth后Nuxt部署到Azure Web App出现内存溢出错误

原本通过GitHub Actions将Nuxt应用部署到Azure Web App正常,添加@sidebase/nuxt-auth模块后,GitHub Actions显示部署成功,但Azure应用提示「:( Application Error」。尝试在工作流中添加NODE_OPTIONS: "--max_old_space_size=4096"提升内存,要么无效果,设置过高时Azure出现超时。本地执行npm run dev和npm run preview均正常,最初部署到静态Web App也遇到相同问题,改用Web App后仍未解决。

Nuxt配置

export default defineNuxtConfig({
    devtools: { enabled: true },
    modules: [
        "@nuxtjs/tailwindcss",
        "@storyblok/nuxt",
        "@sidebase/nuxt-auth",
        "@vueuse/nuxt",
        "@nuxtjs/i18n",
    ],
    storyblok: {
        accessToken: process.env.STORYBLOK_ACCESS_TOKEN,
    },
    runtimeConfig: {
        NUXT_SECRET: process.env.NUXT_SECRET,
        AZURE_AD_CLIENT_ID: process.env.AZURE_AD_CLIENT_ID,
        AZURE_AD_CLIENT_SECRET: process.env.AZURE_AD_CLIENT_SECRET,
        AZURE_AD_TENANT_ID: process.env.AZURE_AD_TENANT_ID,
        public: {}
    },
    auth: {
        baseURL: process.env.BASE_URL,
    },
    i18n: {
        vueI18n: './i18n.config.ts',
        baseUrl: process.env.BASE_URL,
        locales: [
            { code: 'en', language: 'en-GB', name: 'English' },
            { code: 'it', language: 'it-IT', name: 'Italiano' },
        ],
        defaultLocale: 'en',
    },
})

Nuxt Auth Handler

import { NuxtAuthHandler } from '#auth'
import AzureADB2CProvider from "next-auth/providers/azure-ad-b2c";

const config = useRuntimeConfig();

export default NuxtAuthHandler({
    secret: config.NUXT_SECRET,
    providers: [
        AzureADB2CProvider.default({
            clientId: config.AZURE_AD_CLIENT_ID,
            clientSecret: config.AZURE_AD_CLIENT_SECRET,
            tenantId: config.AZURE_AD_TENANT_ID,
            primaryUserFlow: 'B2C_1_susi',
            authorization: { params: { scope: 'offline_access openid' } },
            checks: ['pkce'],
            client: {
                token_endpoint_auth_method: 'none',
            },
        }),
    ],
})

GitHub工作流配置

name: Azure Web App

on:
  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

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

    - name: Install Dependencies
      run: npm ci

    - name: Build Nuxt App
      run: npm run build
      env: # Add environment variables here
        AZURE_AD_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
        AZURE_AD_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
        AZURE_AD_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
        HOST: ${{ secrets.HOST }}
        NUXT_SECRET: ${{ secrets.NUXT_SECRET }}
        BASE_URL: ${{ secrets.BASE_URL }}
        STORYBLOK_ACCESS_TOKEN: ${{ secrets.STORYBLOK_ACCESS_TOKEN }}

    - name: 'Deploy to Azure Web App'
      uses: azure/webapps-deploy@v3
      with:
        app-name: 'my-app'
        publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
        package: '.output'

Azure错误日志

2024-11-21T17:55:31.0312184Z <--- Last few GCs --->
2024-11-21T17:55:31.0312217Z
2024-11-21T17:55:31.0312259Z [76:0x56ca020]    36486 ms: Mark-Compact (reduce) 2047.5 (2062.9) -> 2047.3 (2062.9) MB, 133.15 / 0.03 ms  (+ 19.4 ms in 1 steps since start of marking, biggest step 19.4 ms, walltime since start of marking 178 ms) (average mu = 0.461, current mu = 0.300)
2024-11-21T17:55:31.0312298Z
2024-11-21T17:55:31.0312322Z <--- JS stacktrace --->
2024-11-21T17:55:31.0312364Z
2024-11-21T17:55:31.0312395Z FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
2024-11-21T17:55:31.0312424Z ----- Native stack trace -----
2024-11-21T17:55:31.0312447Z
2024-11-21T17:55:31.0771650Z  1: 0xb80c98 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]
2024-11-21T17:55:31.0783802Z  2: 0xeede90 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
2024-11-21T17:55:31.0792338Z  3: 0xeee177 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
2024-11-21T17:55:31.0800252Z  4: 0x10ffd15  [node]
2024-11-21T17:55:31.0873988Z  5: 0x1117b98 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
2024-11-21T17:55:31.0882703Z  6: 0x10edcb1 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
2024-11-21T17:55:31.0889685Z  7: 0x10eee45 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
2024-11-21T17:55:31.0896798Z  8: 0x10cb566 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
2024-11-21T17:55:31.0969725Z  9: 0x10bd194 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [node]
2024-11-21T17:55:31.0980255Z 10: 0x10bf976 v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString(int, v8::internal::AllocationType) [node]
2024-11-21T17:55:31.1007798Z 11: 0x10bfa2e v8::internal::FactoryBase<v8::internal::Factory>::NewStringFromOneByte(v8::base::Vector<unsigned char const> const&, v8::internal::AllocationType) [node]
2024-11-21T17:55:31.1016307Z 12: 0x15850c4 v8::internal::Uri::Encode(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>, bool) [node]
2024-11-21T17:55:31.1022987Z 13: 0xf76ecb v8::internal::Builtin_GlobalEncodeURI(int, unsigned long*, v8::internal::Isolate*) [node]
2024-11-21T17:55:31.1074606Z 14: 0x1961df6  [node]

解决方向建议

  • 升级Azure服务计划:错误显示内存已达2GB上限,可将Web App服务计划升级到更高规格(如B2或P2v3),获取更多内存资源。
  • 调整运行时内存参数:在Azure应用设置中配置NODE_OPTIONS为--max_old_space_size=2048(匹配当前服务计划内存上限),而非在GitHub Actions中设置,确保运行时生效。
  • 优化Nuxt配置:在Nuxt配置中添加nitro: { compressPublicAssets: true }开启静态资源压缩,减少运行时内存占用;尝试关闭devtools的生产环境启用开关。
  • 排查模块内存占用:临时移除非核心模块(如@storyblok/nuxt),确认是否为多模块叠加导致内存溢出;检查Auth Handler中是否存在内存泄漏逻辑。
  • 启用详细日志:开启Azure应用的诊断日志和详细错误日志,获取内存溢出的具体触发上下文,精准定位问题点。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 01:02:05