3

I'm trying to deploy a Node.js app to elastic beanstalk. The problem is, it fails at the start script every time. I have ec2 configured to use the start script npm start, which executes node app.js (defined in package.json). However, this start script fails in ec2. I get the logged error,

npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myProject start script 'node app.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the Portfolio package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs myProject
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls myProject
npm ERR! There is likely additional logging output above.

What does this mean? Running npm start on my command line in the root directory of the same app that was zipped to AWS works fine, running on localhost. I also have updated both npm and node.js

Here is the file structure zipped to deploy:

.zip

  • node_modules/
  • public/
  • app.js
  • package.json
  • package-lock.json
ThisClark
  • 14,352
  • 10
  • 69
  • 100
Adam.V
  • 779
  • 2
  • 9
  • 25

1 Answers1

3

I faced a problem with similar symptoms on Elastic Beanstalk which was caused by missing npm dependencies. Some dependencies were installed locally in node_modules, but one or two we're installed globally, causing them not to be packaged when zipping for deployment. Unfortunately Elastic Beanstalk's error message is less than helpful in this case and gives a generic error.

Devon Katz
  • 246
  • 1
  • 3
  • Did you find a way around this? – Adam.V Nov 25 '17 at 19:33
  • Yes. Firstly, make absolutely sure that all npm dependencies your project relies on are present in your `package.json` file. Then switch directories in your terminal or command line to your project's root and run `npm install`, which will ensure your `node_modules` folder is populated with correct dependencies specified by your `package.json` file. See [this question](https://stackoverflow.com/questions/8367031/how-do-i-install-package-json-dependencies-in-the-current-directory-using-npm) for more help! – Devon Katz Nov 25 '17 at 19:48
  • After trying out all the possible solutions to fix the 502 bad gateway error, this one finally got it work! – Bojie Shuai Aug 11 '22 at 04:12