An Azure service that provides streamlined full-stack web app development.
Hi @MLU ,
Your managed API on Azure Static Web Apps returns an empty HTTP 500 for every route, no function is ever invoked, and the build and deploy steps in GitHub Actions report success. You have already ruled out CORS, application settings, routing rules and the function body itself (a self-contained api/ping.js returning a fixed 200).
Before anything else, could you share the exact contents of api/package.json (in particular the main and dependencies fields and whether a type field is present) and the folder layout of api/, including whether a host.json and any function.json files exist? Those two things tell us which programming model the host should be loading and rule the registration failures below in or out.
Why a self-contained function can still fail before it runs
Everything you have checked so far sits downstream of function invocation. A 500 with no invocation indicates a failure before your handler runs. One important possibility is that the Functions host discovered zero functions, or failed while loading them. In that state the function body is never reached, so its content is irrelevant to the symptom.
The Node.js worker supports two programming models and they discover functions differently:
- v3 model (file-based): one folder per function containing a
function.json; the code is expected inindex.jsin the same folder unlessscriptFilepoints elsewhere. This is the default when@azure/functionsis not listed inpackage.json. - v4 model (code-centric):
@azure/functions4.x is listed underdependencies(notdevDependencies), and themainfield inpackage.jsonnames the file or glob that callsapp.http(...)to register the function. The migration guide states thathost.jsonandpackage.jsonmust be at the API root and that themainfield must be defined.
A single file at api/ping.js is not sufficient on its own. Under v3 it needs a corresponding function.json, which the host looks for at api/ping/function.json. Under v4 it must be covered by the main entry in package.json and register the function with app.http(...); if main is missing, or points somewhere else, ping.js is never required and app.http is never called. The two models also cannot be mixed: as soon as one v4 function registers, any function.json files are ignored.
Two further variants produce the same outcome and are worth checking in the same pass:
- A module load error in a file loaded through
main(a wrong import path, a missing dependency, a"type": "module"inpackage.jsoncombined withrequireormodule.exports) can prevent the affected registration code, and potentially the registration of every function in the app, from completing. A Q&A thread from 2023 (404 static web app azure function TS) describes exactly this: the asker found a wrong import at the top of one API file, and no handlers were registered as a result. Treat this as a pattern to verify against your own code rather than an established platform rule. - Every external package the deployed API requires must be available at runtime, normally by being listed under
dependenciesinapi/package.json, unless your build bundles it into the output. A package that resolves only locally (a workspace package, a global install) is missing at runtime; a 2022 Q&A thread (Azure Static Web App with Managed Functions cannot find module) shows the resulting "Cannot find module" failure for a monorepo setup.
How to confirm it from the portal
For managed functions the documentation directs you to Application Insights for runtime logs; logs are only available once Application Insights is added. Before that, two portal views can provide clues about whether the managed API was detected successfully:
- In the Static Web App resource, the APIs blade shows one row per environment with the columns Backend Type and Backend Resource Name. When the platform detected a managed functions app, Backend Type reads "Managed" for the Production environment (as described in the 2022 Q&A thread Azure Static Web App not getting response from static web api API Function); when nothing was detected, both columns show a dash. If Production shows no managed backend even though the deployment was supposed to contain
api/ping.js, that is additional evidence that the managed Functions app was not detected or registered. Treat the portal state as a diagnostic clue, not as a documented statement about the exact failure stage. - Users report that the Application Insights blade shows "Add a function to your app to enable App Insights" when zero functions were detected. Treat that as an indicator, not a documented diagnostic contract. The same reports describe this combination, no functions listed while the Diagnose and solve problems blade still counts backend 5xx errors, as the typical signature of a function app that fails to index (Azure/static-web-apps issue #1731, and the Q&A thread StaticWebApp build/deploy job runs successfully but APIs/managed functions are not deployed correctly). Those are user observations, not documented behavior, but they match what you describe.
Reproducing locally
The Static Web Apps CLI runs your API through Azure Functions Core Tools and proxies /api the same way the service does; see Set up local development for Azure Static Web Apps for swa start with --api-location. Core Tools startup output normally shows the functions it discovered and often exposes module-loading or indexing errors that are otherwise hard to see in the managed environment. That output is the closest substitute for the host log you cannot see in Azure.
On forcing Node.js 18
@Allan Solomon Mejia answer already covers this: node:18 is out of support since May 31, 2025 per the supported runtimes table, and platform.apiRuntime in staticwebapp.config.json selects between node:20 and node:22. The point about the config file having to land in the deployed output root is worth checking as well. Switching between 20 and 22 is a legitimate test, but a registration problem of the kind described above persists across both, so if the node:20 test changes nothing, api/package.json and the folder layout are the next place to look.
References
- Azure Functions Node.js developer reference
- Migrate to v4 of the Node.js model for Azure Functions
- API support in Azure Static Web Apps with Azure Functions
- Supported languages and runtimes in Azure Static Web Apps
- Set up local development for Azure Static Web Apps
- Azure/static-web-apps issue #1731
- 404 static web app azure function TS (Microsoft Q&A)
- StaticWebApp build/deploy job runs successfully but APIs/managed functions are not deployed correctly (Microsoft Q&A)
- Azure Static Web App not getting response from static web api API Function (Microsoft Q&A)
- Azure Static Web App with Managed Functions cannot find module (Microsoft Q&A)
Drafted with help from Claude, disclosed per the Q&A AI usage policy. All technical claims checked against the Azure Functions Node.js developer reference, the Node.js v4 migration guide, and the Azure Static Web Apps documentation on API support, supported runtimes and local development.