Azure Static Web App with Managed Functions cannot find module

Muhammed Ensar Ishakoglu 1 Reputation point
2022-06-24T13:53:56.517+00:00

I have a monorepo that contains 5 packages in total:

  • frontend
  • backend
  • library 1
  • library 2
  • library 3

The backend uses the libraries. Whenever I emulate the SWA everything works fine but whenever I deploy the application, I get the error:

Exception while executing function: Functions.npm-dependency-report Result: Failure  
Exception: Worker was unable to load function npm-dependency-report: 'Cannot find module 'rimraf'  
Require stack:  
- /home/site/wwwroot/dist/npm-dependency-report/index.js  
- /azure-functions-host/workers/node/dist/src/worker-bundle.js  
- /azure-functions-host/workers/node/dist/src/nodejsWorker.js'  
Stack: Error: Cannot find module 'rimraf'  
Require stack:  
- /home/site/wwwroot/dist/npm-dependency-report/index.js  
- /azure-functions-host/workers/node/dist/src/worker-bundle.js  
- /azure-functions-host/workers/node/dist/src/nodejsWorker.js  
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)  
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)  
    at Module.require (node:internal/modules/cjs/loader:1005:19)  
    at Object.apply (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:38624)  
    at require (node:internal/modules/cjs/helpers:102:18)  
    at /home/site/wwwroot/dist/npm-dependency-report/index.js:279:5348  
    at /home/site/wwwroot/dist/npm-dependency-report/index.js:1:222  
    at /home/site/wwwroot/dist/npm-dependency-report/index.js:279:12306  
    at /home/site/wwwroot/dist/npm-dependency-report/index.js:1:222  
    at Object.<anonymous> (/home/site/wwwroot/dist/npm-dependency-report/index.js:283:1294)  

The module rimraf is installed and included in the package.json of the backend. Whenever I remove the line that uses rimraf, it gives the same error with another dependency called 'node-gyp', which is not even a dependency of my project, but a dependency of one of my dependencies.

I deployed the application using Azure SWA CLI, and whatever I do, I cannot get rid of the error.

Command used to emulate the SWA: swa start --app-location ./packages/frontend --api-location ./packages/backend --output-location ./dist

Command used to deploy the SWA: swa deploy --app-location ./packages/frontend --api-location ./packages/backend --output-location ./dist

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,929 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,178 questions
{count} votes

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.