Azure Function App suddenly showing error on all environments

Arjan Verus 0 Reputation points
2024-10-08T10:21:03.3233333+00:00

Since last saturday during the night we suddenly see an error appearing when an Azure Function is running. There were no changes from our end in the environment. The same thing happened on all environments, test ,staging and production.

 

The Azure Function is behind a API Management instance, when we run a test on the API Management then we see the same issue appearing.

We use a ZIP deploy and run from package. 

It is a linux function running on EP1 instance.

Runtime version ~4
Node 18 LTS

 

There is a simple ApiHealthCheck function which already shows an error.

We are using prisma to connect to out SQL database.

 

This is the error we see at invocations:

Result: Failure Exception: Worker was unable to load function ApiHealthCheck: 'Cannot find module '.prisma/client/index' Require stack: - /home/site/wwwroot/node_modules/@prisma/client/index.js - /home/site/wwwroot/dist/src/utils/Error.js - /home/site/wwwroot/dist/src/utils/Request.js - /home/site/wwwroot/dist/ApiHealthCheck/index.js - /azure-functions-host/workers/node/dist/src/worker-bundle.js - /azure-functions-host/workers/node/dist/src/nodejsWorker.js' Stack: Error: Worker was unable to load function ApiHealthCheck: 'Cannot find module '.prisma/client/index' Require stack: - /home/site/wwwroot/node_modules/@prisma/client/index.js - /home/site/wwwroot/dist/src/utils/Error.js - /home/site/wwwroot/dist/src/utils/Request.js - /home/site/wwwroot/dist/ApiHealthCheck/index.js - /azure-functions-host/workers/node/dist/src/worker-bundle.js - /azure-functions-host/workers/node/dist/src/nodejsWorker.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15) at Module._load (node:internal/modules/cjs/loader:981:27) at Module.require (node:internal/modules/cjs/loader:1231:19) at Object.apply (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:51713) at require (node:internal/modules/helpers:177:18) at Object.<anonymous> (/home/site/wwwroot/node_modules/@prisma/client/index.js:2:6) at Module._compile (node:internal/modules/cjs/loader:1364:14) at Module._extensions..js (node:internal/modules/cjs/loader:1422:10) at Module.load (node:internal/modules/cjs/loader:1203:32) at Module._load (node:internal/modules/cjs/loader:1019:12)

 

Is anyone experiencing similar behaviour or getting the same kind of error?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,447 questions
Azure SQL Database
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2024-10-10T20:21:19.95+00:00

    The error you're encountering seems to be related to the Prisma client package, specifically that the module .prisma/client/index cannot be found. Since the issue appeared suddenly across all environments without any changes from your side, it's possible that something external has impacted your setup. Here are some potential causes and troubleshooting steps:

    Potential Causes:

    1. File Path Issues: It seems like the deployment may have been corrupted or missed files during the ZIP deployment. Specifically, the Prisma client files are not being found, which could indicate they weren't properly included in the deployed package.
    2. Prisma Client Generation: The Prisma client files are generated at build time. If Prisma wasn’t properly generated during the build, the necessary files won’t be available at runtime.
    3. Node.js Update/Compatibility: Since you're using Node 18 LTS, there might have been an update or a compatibility issue introduced either by Azure or within your deployment pipeline, causing certain packages or files to not load correctly.
    4. Platform Issues (Azure): Given that it’s affecting all environments, there could be an underlying issue with Azure Functions or the Linux platform you're running on, particularly if Azure updated the runtime or infrastructure without notice.

    Troubleshooting Steps:

    1. Rebuild and Redeploy:
      • Try to manually regenerate the Prisma client by running npx prisma generate and ensure the node_modules/.prisma/client folder is present.
      • Rebuild your project and deploy it again using ZIP deployment, ensuring all dependencies are included.
    2. Check run-from-package Setting:
      • When using run-from-package, Azure Functions run directly from the ZIP package. Ensure that the ZIP package includes all the necessary node_modules files, including Prisma.
      • Double-check that WEBSITE_RUN_FROM_PACKAGE is set correctly in your application settings and points to the correct ZIP package.
    3. Verify the Node.js Version:
      • Confirm that the version of Node.js being used on Azure is indeed Node 18 LTS and matches your local environment. You can check this in the Azure Function's settings.
      • Ensure that all dependencies are compatible with Node 18 LTS, including Prisma.
    4. Prisma and SQLite Cache:
      • Prisma might cache certain binaries depending on the environment. You can try clearing Prisma's cache by running npx prisma generate --force before deployment.
    5. Check for Azure Platform Issues:
      • Check if there are any ongoing Azure platform issues, particularly related to the Azure Functions Linux EP1 instance or Prisma-related services. Sometimes Azure may push updates to the platform that could introduce breaking changes.
      • You can check the Azure Status page or reach out to Azure Support to confirm if any recent changes might have impacted your environments.
    6. Local Testing:
      • Test the function locally with the same Node.js version to ensure it works before deploying it to Azure. This will help you identify if the issue is with the deployment process or the Azure environment.
    7. API Management Settings:
      • Test if removing API Management from the flow resolves the issue. This will help identify if the problem is specific to Azure API Management or to the Azure Function itself.

    If the issue persists:

    • Consider turning on detailed logging in Azure Functions and Application Insights to capture more detailed errors or stack traces that may provide additional clues.
    • Reach out to Azure Support if you're unable to resolve the issue, as this could be related to Azure's infrastructure changes.

    Let me know how the troubleshooting goes or if you need further assistance!

    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.