node.js - How do I deploy a Nuxt 3 solution to an Azure Node Web App - Stack Overflow

For the last few days I've been trying to configure an Azure Web App using Node as runtime stack.

For the last few days I've been trying to configure an Azure Web App using Node as runtime stack. All the guides out there talks about Static Web Apps but that does not suit my needs.

I use Github Actions to build and deploy the solution and all checkmarks are green in the end. The site however says ":( Application Error" and the diagnostic resources says: The Resource '.../slots/gfecb4esg8r4dcc7' under resource group 'xxx' was not found.. Since I don't use slots I've tried to remove slot-name: 'Production' from the yaml file to no prevail, the error message stays the same.

  1. What environment variables do I need to configure?
  2. What do I put as Startup Command in the Azure Web App?
  3. What do I put as the start command in package.json?
  4. Am I missing something else?

Here is my yaml file content if necessary:

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

on:
    push:
        branches:
            - main
    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 --if-present
                  npm run test --if-present

            - name: Zip artifact for deployment
              run: zip release.zip ./* -r

            - name: Upload artifact for deployment job
              uses: actions/upload-artifact@v4
              with:
                  name: node-app
                  path: release.zip

    deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
            name: "Production"
            url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
        permissions:
            id-token: write #This is required for requesting the JWT

        steps:
            - name: Download artifact from build job
              uses: actions/download-artifact@v4
              with:
                  name: node-app

            - name: Unzip artifact for deployment
              run: unzip release.zip

            - name: Login to Azure
              uses: azure/login@v2
              with:
                  client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_XXX }}
                  tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_XXX }}
                  subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_XXX }}

            - name: "Deploy to Azure Web App"
              id: deploy-to-webapp
              uses: azure/webapps-deploy@v3
              with:
                  app-name: "myapp"
                  # slot-name: 'Production'
                  package: .

For the last few days I've been trying to configure an Azure Web App using Node as runtime stack. All the guides out there talks about Static Web Apps but that does not suit my needs.

I use Github Actions to build and deploy the solution and all checkmarks are green in the end. The site however says ":( Application Error" and the diagnostic resources says: The Resource '.../slots/gfecb4esg8r4dcc7' under resource group 'xxx' was not found.. Since I don't use slots I've tried to remove slot-name: 'Production' from the yaml file to no prevail, the error message stays the same.

  1. What environment variables do I need to configure?
  2. What do I put as Startup Command in the Azure Web App?
  3. What do I put as the start command in package.json?
  4. Am I missing something else?

Here is my yaml file content if necessary:

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

on:
    push:
        branches:
            - main
    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 --if-present
                  npm run test --if-present

            - name: Zip artifact for deployment
              run: zip release.zip ./* -r

            - name: Upload artifact for deployment job
              uses: actions/upload-artifact@v4
              with:
                  name: node-app
                  path: release.zip

    deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
            name: "Production"
            url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
        permissions:
            id-token: write #This is required for requesting the JWT

        steps:
            - name: Download artifact from build job
              uses: actions/download-artifact@v4
              with:
                  name: node-app

            - name: Unzip artifact for deployment
              run: unzip release.zip

            - name: Login to Azure
              uses: azure/login@v2
              with:
                  client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_XXX }}
                  tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_XXX }}
                  subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_XXX }}

            - name: "Deploy to Azure Web App"
              id: deploy-to-webapp
              uses: azure/webapps-deploy@v3
              with:
                  app-name: "myapp"
                  # slot-name: 'Production'
                  package: .
Share Improve this question asked Nov 20, 2024 at 10:05 tomfritomfri 54 bronze badges 10
  • Share your Azure App service Log stream here. – Aslesha Kantamsetti Commented Nov 20, 2024 at 10:19
  • If possible, share your code? – Aslesha Kantamsetti Commented Nov 20, 2024 at 10:19
  • 1 Thank you for your effort! I end up with the same result and I don't understand what is wrong since the .output folder is missing. I have tried to add "npm run build" in the Startup Command without knowing this is the way to go...? Still it does not work. – tomfri Commented Nov 20, 2024 at 13:19
  • 1 Thank you @AsleshaKantamsetti! Your comments made me look in the right direction and the culprit was .gitignore in combination with the build script. The build script ignored the .output folder since it is included in the .gitignore file. I changed the artifact command to run: zip -r release.zip .output/* and removed all settings in the Startup Command and the Internet is now a better place... ;) – tomfri Commented Nov 20, 2024 at 15:09
  • 1 Please do! Go bananas! – tomfri Commented Nov 20, 2024 at 16:00
 |  Show 5 more comments

1 Answer 1

Reset to default 0

I created sample nuxtjs app and even I got the Application error after deploying it to azure web app through GitHub.

The .output folder is not deployed to Azure through GitHub Actions, even though when we run the npm run build command in workflow file.

  • Workflow file might not include the .output folder in the deployment package. As .output is a hidden folder, we need to directly include it in packaging commands as following in workflow file.

    run: zip -r release.zip .output/*

I added below Start script to package.json:

"scripts": {
"start": "nuxt start"
}

If you want to deploy the application smoothly, you can deploy it via VS Code Azure Extension. As it will add all files automatically.

Goto Azure Extension -> Subscription -> Select Azure Web App -> Right Click hit deploy to web app.

Azure Web App Output:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742366481a4430413.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信