Michele Spina
Michele Spina

Reputation: 1121

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

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.

Upvotes: 42

Views: 25539

Answers (8)

Hayha
Hayha

Reputation: 2240

You can also have this error if your package.json is missing the start command

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js" <-- add this if missing
  },
  "dependencies": {
  }
}

Upvotes: 0

Arefe
Arefe

Reputation: 12441

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

Upvotes: 1

Carma
Carma

Reputation: 1

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

Upvotes: 0

frank3stein
frank3stein

Reputation: 706

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.

Upvotes: 1

LYu
LYu

Reputation: 2426

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.

Upvotes: 0

Chandra Sekhar
Chandra Sekhar

Reputation: 16516

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

Upvotes: 24

Federico
Federico

Reputation: 6478

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

Upvotes: 56

Rob
Rob

Reputation: 353

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.

Upvotes: 1

Related Questions