Managed functions not registering when deployed

GaryParr 46 Reputation points
2024-11-06T04:10:59.88+00:00

SWA was working fine last year. Stepped away from development for a while. Came back to it and pushed some changes out. Deployment succeeded with no errors but SWA says I have no functions now. Pipeline is DevOps...

User's image

No errors in the pipeline, but the SWA portal app shows I have no backend...

User's imageTrying to hit an api just throws a 404. Everything works fine in local development, so no idea what's going on. I've seen someone with a similar issue who said the answer was to move all dev dependencies to regular dependencies. That didn't work for me... only dev dependencies are typescript and types/node. Another similar issue ended up being the skip_api_build flag. Again, not the issue here.

Any ideas?

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,173 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Alnis Smidchens 5 Reputation points
    2025-01-23T04:02:43.36+00:00

    I had the same symptoms: API works locally, logs say deployment was successful, but no back end shows up in the Azure portal.

    My problem was that I had a require('./some-file') in one of my back-end JavaScript files where some-file.js was in the .gitignore, so it worked locally, but not when pushed.

    <wall-of-text>

    So—and I'm speculating here—it makes me think that if your code throws an exception while defining the endpoints AND that exception only throws in Azure (not locally), it will result in a silent failure. The artifacts are uploaded from your CI/CD pipeline to Azure, but since the error happens somewhere during deployment in Azure and not during a request to a function, you get in a state where your build pipeline thinks everything was OK even though the functions never got defined in Azure.

    Evidence that supports my speculation is that adding throw new Error('NONSENSE that will break things'); in a file for the back end outside of the function/API definition results in the same exact apparent failure where the application starts, but no functions are registered—EXCEPT in this case it also fails to deploy any functions locally with errors in the logs and a message No job functions found., followed by a message that the CLI emulator is serving the API (even though none of the functions respond/are defined).

    I replicated this across both a project deploying from GitHub Actions and from a project deploying from GitLab, and in both cases the deploy job in GitHub/GitLab was successful with clean logs, and the endpoints got busted in Azure. So, I think if you make a setup where an exception gets thrown during function definition, only "in production" (not on your machine), then you'll have the observed behavior.

    Also, I tried to access logs based on the command provided by @brtrach-MSFT :
    az webapp log tail --name <your-app-name> --resource-group <your-resource-group>

    ...however, it failed for me with the error:

    (ResourceNotFound) The Resource 'Microsoft.Web/sites/MY_APP_NAME' under resource group 'MY_RESOURCE_GROUP_NAME' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

    I should note that using az resource list shows the type of my static web app as Microsoft.Web/staticSites, which does not match Microsoft.Web/sites—the type the az webapp log command mentioned.

    It seems that the CLI for static web apps is az staticwebapp, but that does not have a way to inspect logs. (logs for Static Web Apps are provided by Application Insights, but I can't find a way to buy Application Insights for a project where function deployment is failing like this...)

    </wall-of-text>

    Based on that wall of text, I propose 2 things:

    • Users of Azure Static Web Apps encountering this issue: check your project for errors that could happen during function definition — e.g., require()-ing gitignored files.
    • Microsoft Azure team: if my speculation about the cause is correct, please make deployment jobs fail if an exception is thrown during function definition. This will both prevent bad deployments, and help debug the root cause of the problem.

    Annotated screenshot of the deployment logs for a "successful" deploy where functions did not get defined due to an exception getting thrown during function definition:

    Screenshot 2025-01-22 at 7.57.18 PM

    I should note—this is my speculative hypothesis as a user, so I could be missing something, or your problem could be something else, but hopefully there was something helpful in here!

    Edit to add: I logged a bug report in the Microsoft feedback portal to track this issue: https://feedback.azure.com/d365community/idea/ee54d1c5-59d9-ef11-95f5-6045bd80c607

    1 person found this answer helpful.

  2. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2024-12-19T06:49:45.13+00:00

    @GaryParr This is certainly a frustrating situation. I've seen this with a few other customers and have a few thoughts to share for you and/or the community.

    First, check your Azure Function configuration. Ensure that your host.json and local.settings.json files are correctly set up. Additionally, verify that your function app settings in the Azure portal are accurate and match your local development environment.

    Review your deployment pipeline. Double-check the configuration in your DevOps pipeline to ensure all necessary build tasks are included. Make sure the api_location in your staticwebapp.config.json is correctly specified to point to your API.

    Inspecting logs can be crucial for troubleshooting. Although accessing logs might be challenging, you can use the Azure CLI to fetch logs by running the command az webapp log tail --name <your-app-name> --resource-group <your-resource-group>. This might provide more insight into what’s going wrong during deployment.

    Regarding dependency management, since moving dev dependencies to regular dependencies didn't resolve the issue, ensure that all necessary runtime dependencies are included in your package.json. This can help avoid any missing dependencies that might be causing the problem.

    You've already checked for duplicate function names, but also ensure there are no naming conflicts or reserved keywords being used in your function names. This can sometimes cause unexpected issues.

    Additionally, check for any quota or limit issues on your Azure subscription. Deployment problems can sometimes be related to hitting quota limits, so verify that you haven't exceeded any limits on your account.

    0 comments No comments

Your answer

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