错误:当我通过 Github 操作上传 Next.js 网站时,无法在 Azure Web 服务上的“./.next”目录中找到生产版本

问题描述 投票:0回答:1

我尝试通过 github 操作将 shell Next.js 应用程序上传到 Azure Web 服务,但出现错误。

“错误:在‘./.next’目录中找不到生产版本。在启动生产服务器之前尝试使用‘next build’构建您的应用程序。”

我的神器的文件夹结构是

应用程序

节点模块

包装

服务器.js

我的启动命令是node server.js

这是我的 yml 文件:

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

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    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
      
      - name: Copy static files
        run: |
          cp -R ./.next/static ./.next/standalone/.next/static

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: app
          path: .next/standalone

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: Production
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: app
      
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'frontend'
          slot-name: 'Production'
          package: .
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}

我已关注:

https://inmeta.medium.com/deploy-next-js-to-azure-3- effective-strategies-for-modern-developers-86a41c0f9d92https://www.youtube.com/watch? v=H4amPlNBTf0 如何配置的示例,但仍然遇到问题。

有谁知道为什么会这样吗?

next.js github-actions azure-webapps
1个回答
0
投票

actions/upload-artifact@v4
默认不再上传隐藏文件和文件夹。

为了解决您的问题,您需要将

include-hidden-files: true
添加到您的工作流程文件中,如下所示:

 - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: app
          path: .next/standalone
          include-hidden-files: true

您可以在此处查看 @v4 中包含的重大更改。

© www.soinside.com 2019 - 2024. All rights reserved.