Why am I receiving a missing module error when building my Node.js app on App Platform ?

App Platform throws this error when a module required to run the app is missing from the dependencies section of the app’s package.json file. The error usually looks like this:

Error: Cannot find module 'exampleModule'
[2022-11-01 00:59:32] Require stack:
[2022-11-01 00:59:32] - /workspace/server.js
[2022-11-01 00:59:32] at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
[2022-11-01 00:59:32] at Function.Module._load (node:internal/modules/cjs/loader:833:27)
[2022-11-01 00:59:32] at Module.require
: 
:
(node:internal/modules/cjs/loader:868:12)
[2022-11-01 00:59:32] at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
[2022-11-01 00:59:32] code: 'MODULE_NOT_FOUND',

Sometimes developers mistakenly list the missing module in the devDependencies section of the package.json file instead of the dependencies section. The devDependencies section’s purpose is to list modules that are required to develop the app, such as linters and testing libraries. App Platform prunes the modules listed in the devDependencies section during the build process as they are not required to run the app. This process removes any modules that may have been erroneously listed in the devDependencies section.

To fix this problem, add the missing module to the dependencies section of your app’s package.json file. Alternatively, you can configure App Platform to skip the pruning process during deployment by setting one of the following environment variables:

  • For npm: NPM_CONFIG_PRODUCTION=false
  • For Yarn: YARN_PRODUCTION=false
If an app’s health check fails, the app currently does not restart. This is because App Platform does not currently support liveness probes. An app only automatically restarts if the app crashes or if its disk or RAM usage exceeds the its limits.
You can find the client IP address of a request connecting to your app in the do-connecting-ip HTTP header.
Timeouts can be caused by high CPU utilization, so check your app’s CPU utilization and consider scaling your app.
In this article...