24

I'm very new with amazon web services, and I am trying to set up a node.js app on their elastic beanstalk. I set up the instance and uploaded/deployed the site, but while the health is "Ok" the node.js logs show this repeated about 30 times:

npm ERR! enoent ENOENT: no such file or directory, open '/var/app/current/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log
npm ERR! Linux 4.1.13-19.31.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/npm" "start"
npm ERR! node v4.2.3
npm ERR! npm  v2.14.7
npm ERR! path /var/app/current/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

The problem is that my package.json does exist because I generated one with npm init. Any ideas on why it cant be found? Here is the package.json

{
    "name": "testwebsite",
    "version": "0.0.1",
    "scripts": {
        "start": "node server.js"
    },
    "dependencies": {
        "body-parser": "^1.13.3",
        "express": "^4.13.3",
        "express-session": "~1.0.0",
        "socket.io": "^1.3.7"
    },
    "description": "my website",
    "author": "Matt",
    "engines": {
        "node": ">=0.10.0"
    },
    "main": "server.js",
    "devDependencies": {},
    "license": "ISC"
}
user3281826
  • 277
  • 1
  • 2
  • 8

5 Answers5

49

From an official AWS thread[1], it appears (and this was my problem) that you might be zipping the top-level directory rather than zipping the source itself.

For example, you may have all of your files in a folder called "Project". Rather than zipping "Project", you should zip and upload the contents of "Project".

[1] https://forums.aws.amazon.com/thread.jspa?messageID=476022

  • 1
    I dismissed this at first, but then realized that I **was** doing it wrong! – aero Jun 03 '17 at 04:22
  • The AWS instructions for explicitly how to do this are here: https://aws.amazon.com/blogs/devops/creating-deployable-app-archives-for-elastic-beanstalk/ I particularly appreciated the `git archive --format=zip HEAD > myapp.zip` command. – jgrumps Feb 26 '20 at 17:01
3

I had a problem the same as - or very similar to this, and it was caused the fact that my code was listening to a custom port, instead of the one that Elastic Beanstalk sets as an environment variable (8081).

I fixed this setting in the port near top of my app.js or server.js file, just after I create the express app. For example:

var app = express();
app.set('port', (process.env.PORT || 5000)); // 5000 was my original port

Then using this port in the app.listen method instead of my own custom port number:

app.listen(app.get('port'), function () {
    console.log('Server has started! http://localhost:' + app.get('port') + '/');
});

More details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy

shrewdbeans
  • 11,971
  • 23
  • 69
  • 115
  • Woot! Thank you! – aero Jun 02 '17 at 20:33
  • 1
    Thanks this helped with LoopbackJS hosting on AWS Elastic Beanstalk too. Here i had to go and change the config.json to port 8081. There are better ways to manage different ports by using separate config file overloads. https://loopback.io/doc/en/lb3/Environment-specific-configuration.html Without this change, it kept throwing a 502 Bad Gateway error as the default port was set to 3000 – Swaroop Nov 26 '17 at 11:34
1

I was having these odd error on AWS EB as well. I was generally deploying using the CLI.

couple things to try.

  1. make sure the package.json is not in your .gitignore file, to ensure it is being committed to your repository. EB uses the git commit history to decide what to zip and send. If that isnt included it is not on the AWS servers

  2. i was using the t2.nano instance (512MB space) option for EC and that seemed to be an issue because I had a lot of modules in my package.json. Wasnt sure if that was the root issue of my woes but my error messages changed when I upgraded to an instance that had at least 1GB of space.

hope this helps

Tope
  • 938
  • 2
  • 11
  • 15
0

I was having something similar whereby the elastic beanstalk deploy failed when using the eb cli. I realized that the elastic beanstalk config files had inadvertently been added to my .gitignore file causing the deploy to fail.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mcadamm4
  • 45
  • 6
0

I had trouble with the zipping, etc. I recommend using CodePipeline and linking it to your github or AWS codecommit. Then, skip the build stage, and for the deploy stage click elastic beanstalk.

You will have to pause the process and open a new tab and go to EB and create a new environment. Make sure you click nodeJS in this example. Make sure you choose "sample code" so that AWS can set it up with their template. Once the EB is finished building you should have a link to the template that is functional.

Then you can go back to your CodePipeline tab and click on Elastic Beanstalk for deployment and you should find the EB you just made.

I recommend this process because it will automatically update every time you do a git change. This is better than zipping a file, etc.

Evan Erickson
  • 471
  • 5
  • 12