39

When I try to upload my Node.js project on Elastic Beanstalk I obtain the following error:

Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js.

However, I have the package.json in the main directory.

Michele Spina
  • 1,091
  • 4
  • 12
  • 21

7 Answers7

52

A couple of people were zipping the parent folder incorrectly. You need to select all the contents of the folder and zip those.

https://forums.aws.amazon.com/message.jspa?messageID=477087 https://forums.aws.amazon.com/thread.jspa?threadID=130140&tstart=0

Federico
  • 6,388
  • 6
  • 35
  • 43
23

While uploading the .zip file (Nodejs application) we need to select all the files in the folder, then zip it as shown in below screenshot.

Then upload the Nodejs(zip file) project in AWS Elastic Beanstalck.

enter image description here

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
  • 1
    Do we zip up the `node_modules/` directory as well? – Kenny Worden Dec 03 '19 at 15:17
  • @KennyWorden Of course. Otherwise, how do you expect the app to run? LOL – Arefe Sep 01 '21 at 12:22
  • 2
    @Arefe Idk. Maybe Elastic Beanstalk would install the dependencies from the `package.json`? It's not immediately clear. LOL – Kenny Worden Sep 01 '21 at 22:49
  • @KennyWorden Generally, you will need to build the codebase before you can deploy. However, this instruction can be provided in the CI/CD pipeline as well. – Arefe Sep 02 '21 at 12:03
  • @KennyWorden I think the info provided was not correct. Include a package.json file in the root of your project source to specify dependency packages and to provide a start command. When a package.json file is present, Elastic Beanstalk runs npm install to install dependencies. It also uses the start command to start your application. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-dependencies.html – Arefe Sep 04 '21 at 02:07
1

I had the same issue running a zip of node js boilerplate. It worked when I removed .git and .idea directories and n.gitignore file from the zip.

Rob
  • 353
  • 4
  • 16
1

You need to zip the build directory, to do so inside that directory you can zip -r upload.zip . (do not forget the dot at the end for current directory).

So in that directory you need to have your index.js or server.js as EB looks for how to run the app in the directory only and will not look into folders src, dist etc.

frank3stein
  • 706
  • 2
  • 7
  • 16
1

This can be the packaging issue. You will need to go inside the project and compress altogether as provided in the screenshot:

enter image description here

Arefe
  • 11,321
  • 18
  • 114
  • 168
0

If you use eb cli, make sure you have git committed all the changes.

If you do zip and upload, make sure you don't zip the parent folder but selecting all files and zip.

LYu
  • 2,316
  • 4
  • 21
  • 38
0

In my case i have found a wrong copy of the folder .elasticbeanstalk with inside another config.yml

example

root_project_folder 
    .elasticbeanstalk/
         config.yml
    public/
         .elasticbeanstalk/
              config.yml

and when I started the "eb deploy" command it failed because use the wrong public/ folder as a ROOT

removing the public/.elasticbeanstalk/ have resolved my issue Ciao

Carma
  • 1
  • 1