Search code examples
node.jsamazon-web-servicesamazon-elastic-beanstalk

AWS Elastic beanstalk failed to import modules


i'm trying to deploy my nodejs API to AWS using Elastic beanstalk but keeps getting a 502 Bad Gate way and after getting the logs i found that i have been able to load the imported files and modules. here is a peak on the logs

/var/log/web.stdout.log
----------------------------------------
Jan 26 22:58:01 ip-172-31-88-38 web: > marketeers-backend@1.0.0 start /var/app/current
Jan 26 22:58:01 ip-172-31-88-38 web: > node server.js
Jan 26 22:58:01 ip-172-31-88-38 web: internal/process/esm_loader.js:74
Jan 26 22:58:01 ip-172-31-88-38 web: internalBinding('errors').triggerUncaughtException(
Jan 26 22:58:01 ip-172-31-88-38 web: ^
Jan 26 22:58:01 ip-172-31-88-38 web: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/app/current/src/Models/Admin.js' imported from /var/app/current/src/controllers/AdminController.js
Jan 26 22:58:01 ip-172-31-88-38 web: at new NodeError (internal/errors.js:322:7)
Jan 26 22:58:01 ip-172-31-88-38 web: at finalizeResolution (internal/modules/esm/resolve.js:308:11)
Jan 26 22:58:01 ip-172-31-88-38 web: at moduleResolve (internal/modules/esm/resolve.js:731:10)
Jan 26 22:58:01 ip-172-31-88-38 web: at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
Jan 26 22:58:01 ip-172-31-88-38 web: at Loader.resolve (internal/modules/esm/loader.js:89:40)
Jan 26 22:58:01 ip-172-31-88-38 web: at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
Jan 26 22:58:01 ip-172-31-88-38 web: at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:76:40)
Jan 26 22:58:01 ip-172-31-88-38 web: at link (internal/modules/esm/module_job.js:75:36) {
Jan 26 22:58:01 ip-172-31-88-38 web: code: 'ERR_MODULE_NOT_FOUND'
Jan 26 22:58:01 ip-172-31-88-38 web: }
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! code ELIFECYCLE
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! errno 1
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! marketeers-backend@1.0.0 start: `node server.js`
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! Exit status 1
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR!
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! Failed at the marketeers-backend@1.0.0 start script.
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR! A complete log of this run can be found in:
Jan 26 22:58:01 ip-172-31-88-38 web: npm ERR!     /home/webapp/.npm/_logs/2022-01-26T22_58_01_636Z-debug.log
Jan 26 22:58:02 ip-172-31-88-38 web: > marketeers-backend@1.0.0 start /var/app/current
Jan 26 22:58:02 ip-172-31-88-38 web: > node server.js
Jan 26 22:58:02 ip-172-31-88-38 web: internal/process/esm_loader.js:74
Jan 26 22:58:02 ip-172-31-88-38 web: internalBinding('errors').triggerUncaughtException(
Jan 26 22:58:02 ip-172-31-88-38 web: ^
Jan 26 22:58:02 ip-172-31-88-38 web: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/app/current/src/Models/Admin.js' imported from /var/app/current/src/controllers/AdminController.js

however the API works perfectly fine locally on the development environment. any clues on what is causing this problem.


Solution

  • it seems that the problem was a typo. I'm using Windows for local development which is path case insensitive. but the production environment is Linux which is a case sensitive and that what was causing the problem since I was trying to import the module from Models directory where it was named models