Next not found in deploying teh >Next project on the Azure App Service

Habiba Asif 85 Reputation points
2025-05-29T06:24:39.57+00:00

I am trying to publish the app on the azure app service via github actions I am getting the successful deployment in the github actions but I am not seeing my website and getting the following errors.

User's image

User's image

I have tried multiple combinations of making the next folder changing workflows, package.json but nothings happening still getting the next not found issue

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.


Answer accepted by question author
Anonymous
2025-05-30T03:25:18.77+00:00

Hi Habiba Asif,

The next: not found error occurs because node_modules is excluded from the deployment zip, and Azure's npm install --production may miss critical dependencies for Next.js.

Please try the updated code below.

# 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
on:
  push:
    branches:
      - main
      - payment
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4
      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '22.x'
      - name: npm install and build
        run: |
          npm ci
          npm run build
      - name: Create deployment package
        run: |
          # Remove dev dependencies but keep the built app
          npm prune --production
          # Create zip with all necessary files including node_modules
          zip -r release.zip . -x "*.git*" "*.github*" "*node_modules/.cache*"
      - 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
      contents: read
    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_F897BD80 }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_D28DA4E6 }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_C932F75D3F1C41E9A6 }}
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'my-app-name-qa'
          slot-name: 'Production'
          package: .

Made key changes to improve deployment, replaced npm install with npm ci for consistent installs, added npm prune --production to strip dev dependencies, updated the zip command to include node_modules, and removed the test step to streamline the process.

Please accept as "Yes" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Anonymous
    2025-05-29T11:26:21.02+00:00

    Hi Habiba Asif,

    Your Next.js app is running on Azure App Service with Easy Auth (Microsoft Entra authentication) enabled. This is blocking your app’s API call to https://dev-empiric.azurewebsites.net/api/auth/session because the request isn’t authenticated.

    The error UntrustedHost: Host must be trusted means your app doesn't trust the Azure domain yet. You'll need to update your app’s authentication settings to recognize the Azure domain as a trusted host.

    Your app worked before because Easy Auth wasn't turned on. Once you enabled Microsoft Entra authentication, it started blocking all requests—including those to your NextAuth.js API routes—causing the current authentication issue.

    Option 1: Allow NextAuth.js to manage authentication

    1). Disable Azure Authentication (Easy Auth):

    • Go to your App Service → Authentication
    • Turn off App Service Authentication

    2). Update your NextAuth config to trust the Azure domain

    // pages/api/auth/[...nextauth].js or app/api/auth/[...nextauth]/route.js
    import NextAuth from 'next-auth'
    export const authOptions = {
      // your existing config and providers
      trustHost: true,
      trustedHosts: [
        'https://dev-empiric.azurewebsites.net',
        'http://localhost:3000'
      ]
    };
    export default NextAuth(authOptions);
    

    3). Set environment variables in Azure App Service -> Configuration

    NextAuth.js Deployment

    NEXTAUTH_URL=https://dev-empiric.azurewebsites.net
    NEXTAUTH_URL_INTERNAL=https://dev-empiric.azurewebsites.net
    NEXTAUTH_SECRET=your-secret-key
    

    4). Redeploy and Restart the App

    Option 2: Keep Azure Authentication enabled

    If you need Azure Easy Auth (e.g., for corporate sign-in), you’ll need to configure it so it doesn’t block your API endpoints:

    • Go to App Service -> Authentication
    • Set Unauthenticated requests to Allow anonymous requests
    • Let your app handle login at /api/auth/signin using NextAuth.js

    Please see the documents below for your reference.

    Azure App Service - Overview of Authentication/Authorization

    Configure Entra ID Auth Provider – App Service (workforce)

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.