42

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.

8 Answers 8

56

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

Sign up to request clarification or add additional context in comments.

2 Comments

I thought I only needed to do this on Windows, but even on macOS you have to do this same thing!
How we can do this when using AWS code pipeline?
24

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

6 Comments

Do we zip up the node_modules/ directory as well?
@KennyWorden Of course. Otherwise, how do you expect the app to run? LOL
@Arefe Idk. Maybe Elastic Beanstalk would install the dependencies from the package.json? It's not immediately clear. LOL
@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.
@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. docs.aws.amazon.com/elasticbeanstalk/latest/dg/…
|
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.

Comments

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.

Comments

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

Comments

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.

1 Comment

Yes, or use eb deploy --staged to deploy also the uncommitted files.
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

1 Comment

Can you add your solution as answer and accept it?
0

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": {
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.