【问题标题】:Problem with Deploying Next.js to Azure App Service using Github Actions使用 Github Actions 将 Next.js 部署到 Azure 应用服务的问题
【发布时间】:2021-10-16 08:58:25
【问题描述】:

我目前使用 github 操作将 next.js 部署到 azure 应用服务时遇到问题。 虽然我正在尝试部署,但我不断收到一条错误消息,提示“没有这样的文件或目录”

yaml文件和下面的一样

Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

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

on: 
  push:
    branches:
      - master 
  
env:
  AZURE_WEPAPP_NAME: clsreact3
  AZURE_WEBAPP_PACKAGE_PATH: '.'
  NODE_VERSION: '14.x'

jobs:
  build-and-deploy:
    name: Build and Deploy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@main
    - name: Use Node.js ${{ env.NODE_VERSION }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ env.NODE_VERSION }}
    - name: npm install, build, and test
      run: |
        # Build and test the project, then
        # deploy to Azure Web App.
        npm install
        npm run build --if-present
        npm run test --if-present
      working-directory: my-app-path
    - name: 'Deploy to Azure WebApp'
      uses: azure/webapps-deploy@v2
      with: 
        app-name: ${{ env.AZURE_WEBAPP_NAME }}
        publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
        package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

如果需要更多信息,请参阅此处。 https://github.com/scl2589/next.js-tutorial

谢谢:)

【问题讨论】:

  • 不确定错误,但您的项目显示不正确。在 package.json 你有启动脚本(和开发脚本):node server.js 而你的项目没有server.js 文件。此外,避免混合包管理器。我可以看到yarn.lockpackage-lock.json。您确定该项目甚至可以在您的系统上运行吗?另外,不要结帐node_modules。将其添加到.gitignore

标签: azure next.js azure-web-app-service github-actions


【解决方案1】:

所以你错了working-directory: my-app-path,为了确保你使用正确的工作目录,请在之前添加这个步骤:

 - name: List directory
      run: |
         ls .

我无法提供更好的答案,因为我不知道您的项目结构。

【讨论】:

    【解决方案2】:

    我正在使用他们的本地 git 部署方法。通过创建一个远程(命名为azure)引用 azure 应用服务的 git(您可以在部署部分获取它)。

    我在我的存储库(在主分支上)完成我的任务,然后我只是这样做来部署

    git pull origin master
    git push azure master
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-25
      • 2020-10-16
      • 2021-07-10
      • 2017-11-27
      • 2019-08-14
      • 2020-07-30
      • 2021-08-25
      • 2020-04-17
      相关资源
      最近更新 更多