2

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

  • Were you able to solve this? – Aijaz Sep 16 '22 at 03:16
  • @Aijaz I think bundling the package which had the error fixed the issue. I used esbuild to bundle all the dependencies of my backend (the one that throwed the 'Cannot find module') in to one js file. Deploying this js file fixed the issue – Ensar Ishakoglu Sep 20 '22 at 11:58
  • So I think thi is caused by library1..3 not being inside backend (inside --api-location folder). I think that SWA will only publish content of --app-location+--output-location and --api-location. In your case SWA publishes all content of folder ./packages/frontend/dist and ./packages/backend. This means that ./packages/library1..3 folders are NEVER published to azure and thus require statement fails as they are NOT there. – Luk Deathrage Prochzka Sep 23 '22 at 14:01

0 Answers0