Azure Static Web App with Managed Functions cannot find module

Viewed 135

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

1 Answers

Stack: Error: Cannot find module 'rimraf'

Try to install the rimraf by global scope as per this below sample code.

npm install rimraf -g

And the other error after you removed those lines.

Whenever I remove the line that uses rimraf, it gives the same error with another dependency called 'node-gyp'

Recheck the version of your msvs_version.

Here is the working solution for the same, from devman81's answer here:

npm config set msvs_version 2013 --global
Related