0

I try to deploy my static webapp with a managed function to Azure but the function deployment always fails and I don't know why. I used Node v20 and v18. I downgraded my libraries. I tried every structure i found online. enter image description here

I currently only use a very simple function to test, but even that fails. Thats my index.js:

app.setup({
  enableHttpStream: true,
});

// Add your function definition
app.http("assessmentStoring", {
  methods: ["GET", "POST"],
  authLevel: "anonymous",
  handler: async (request, context) => {
    // Your function logic from assessmentStoring.js
    return { status: 200, body: "Hello from Azure Functions!" };
  },
});

Thats my function.json:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": ["get", "post"]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "scriptFile": "index.js"
}

Thats my action yml:

name: Azure Static Web Apps CI/CD

on:
  push:
    branches: [main]
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches: [main]

env:
  AZURE_FUNCTIONS_ENVIRONMENT: Production

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
          lfs: false

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "22.18.0"
          cache: "npm"

      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.TOKEN}}
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          action: "upload"
          app_location: "/"
          api_location: "api"
          output_location: "out"
          skip_api_build: false
          skip_app_build: false
        env:
          IS_STATIC_EXPORT: true
          AZURE_FUNCTIONS_ENVIRONMENT: Production
          NEXT_TELEMETRY_DISABLED: 1
          NEXT_BUILD_CACHE: "true"

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.TOKEN}}
          action: "close"
          app_location: "."

Thats my package.json:

{
  "name": "api",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {
    "@azure/functions": "^4.0.0"
  },
  "main": "src/index.js",
  "type": "module",
  "engines": {
    "node": "18.x"
  }
}

And thats my host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

Can anybody tell me why it wont work? I am desperate :c

4
  • Do you get some error message when deploying? Can you share it? Commented Aug 26 at 23:34
  • Move index.js and function.json to the root of the api/ folder. Delete function.json if using the v4 programming model.remove function.json entirely. The bindings are inferred from the app.http() declaration. Set node-version: "18.x" in your GitHub Action. Ensure azure-functions-core-tools is installed for local testing. Add it as a dev dependency or install globally npm install -g azure-functions-core-tools@4 --unsafe-perm true Commented Aug 26 at 23:46
  • ---End of Oryx build logs--- Function Runtime Information. OS: linux, Functions Runtime: ~4, node version: 18 Finished building function app with Oryx Zipping Api Artifacts Done Zipping Api Artifacts Zipping App Artifacts Done Zipping App Artifacts Uploading build artifacts. Finished Upload. Polling on deployment. Status: InProgress. Time: 0.2178821(s) Status: Failed. Time: 17.9270468(s) Deployment Failed :( Deployment Failure Reason: Failed to deploy the Azure Functions. Thats the only error i get Commented Aug 27 at 11:26
  • @HarishBadijana i tried this, it didnt work :c Commented Aug 27 at 15:36

1 Answer 1

1
  1. Function.json conflict: You were mixing v3 (function.json) with v4 (programming model) syntax

  2. Wrong file locations: package.json is in the wrong place

  3. Node version mismatch: Using 22.x in workflow but 18.x in package.json

  4. Missing static export configuration: Next.js wasn't configured for static export

can you try this project structure

enter image description here

Remove the function.json file (not needed with v4 programming model)

api/src/index.js

import { app } from '@azure/functions';

app.setup({
  enableHttpStream: true,
});

// Add your function definition
app.http("assessmentStoring", {
  methods: ["GET", "POST"],
  authLevel: "anonymous",
  handler: async (request, context) => {
    // Your function logic from assessmentStoring.js
    return { status: 200, body: "Hello from Azure Functions!" };
  },
});

api/package.json

{
  "name": "api",
  "version": "1.0.0",
  "description": "Azure Functions API",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {
    "@azure/functions": "^4.0.0"
  },
  "main": "src/index.js",
  "type": "module",
  "engines": {
    "node": "18.x"
  }
}

GitHub Workflow:

change node.js version to 18.x . keep in consistent in package.json and workflow

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  trailingSlash: true,
  images: {
    unoptimized: true
  }
}

module.exports = nextConfig

Make sure your secrets are properly configured (TOKEN)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.