Troubleshoot Node.js apps in Azure Functions

Important

The content of this article changes based on your choice of the Node.js programming model in the selector at the top of the page. The v4 model is currently in preview and is designed to have a more flexible and intuitive experience for JavaScript and TypeScript developers. Learn more about the differences between v3 and v4 in the upgrade guide.

This article provides a guide for troubleshooting common scenarios in Node.js function apps.

The Diagnose and solve problems tab in the Azure portal is a useful resource to monitor and diagnose possible issues related to your application. It also supplies potential solutions to your problems based on the diagnosis.

Another useful resource is the Logs tab in the Azure portal for your Application Insights instance so that you can run custom KQL queries. The following example query shows how to view errors and warnings for your app in the past day:

let myAppName = "<your app name>";
let startTime = ago(1d);
let endTime = now();
union traces,requests,exceptions
| where cloud_RoleName =~ myAppName
| where timestamp between (startTime .. endTime)
| where severityLevel > 2

If those resources didn't solve your problem, the following sections provide advice for specific application issues:

No functions found

If you see any of the following errors in your logs:

No HTTP triggers found.

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Try the following fixes:

  • When running locally, make sure you're using Azure Functions Core Tools v4.0.5382 or higher.
  • When running in Azure:
    • Make sure you're using Azure Functions Runtime Version 4.25 or higher.

    • Make sure you're using Node.js v18 or higher.

    • Set the app setting FUNCTIONS_NODE_BLOCK_ON_ENTRY_POINT_ERROR to true. This setting is recommended for all model v4 apps and ensures that all entry point errors are visible in your application insights logs. For more information, see App settings reference for Azure Functions.

    • Check your function app logs for entry point errors. The following example query shows how to view entry point errors for your app in the past day:

      let myAppName = "<your app name>";
      let startTime = ago(1d);
      let endTime = now();
      union traces,requests,exceptions
      | where cloud_RoleName =~ myAppName
      | where timestamp between (startTime .. endTime)
      | where severityLevel > 2
      | where message has "entry point"
      
  • Make sure your app has the required folder structure with a host.json at the root and a folder for each function containing a function.json file.

Undici request is not a constructor

If you get the following error in your function app logs:

System.Private.CoreLib: Exception while executing function: Functions.httpTrigger1. System.Private.CoreLib: Result: Failure Exception: undici_1.Request is not a constructor

Make sure you're using Node.js version 18.x or higher.

Failed to detect the Azure Functions runtime

If you get the following error in your function app logs:

WARNING: Failed to detect the Azure Functions runtime. Switching "@azure/functions" package to test mode - not all features are supported.

Check your package.json file for a reference to applicationinsights and make sure the version is ^2.7.1 or higher. After updating the version, run npm install

Get help from Microsoft

You can get more help from Microsoft in one of the following ways:

  • Search the known issues in the Azure Functions Node.js repository. If you don't see your issue mentioned, create a new issue and let us know what has happened.
  • If you're not able to diagnose your problem using this guide, Microsoft support engineers are available to help diagnose issues with your application. Microsoft offers various support plans. Create a support ticket in the Support + troubleshooting section of your function app page in the Azure portal.

Next steps