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
Asked Answered
B

8

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.

Betweenwhiles answered 17/12, 2013 at 12:27 Comment(0)
A
54

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

Agonistic answered 15/8, 2014 at 16:40 Comment(2)
I thought I only needed to do this on Windows, but even on macOS you have to do this same thing!Jacquie
How we can do this when using AWS code pipeline?Opening
P
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

Preciosity answered 17/8, 2016 at 9:21 Comment(6)
Do we zip up the node_modules/ directory as well?Butterfat
@KennyWorden Of course. Otherwise, how do you expect the app to run? LOLBocock
@Bocock Idk. Maybe Elastic Beanstalk would install the dependencies from the package.json? It's not immediately clear. LOLButterfat
@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.Bocock
@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/…Bocock
I am using the code pipeline, this solution is not applicable in that caseOpening
P
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.

Phlegethon answered 13/4, 2014 at 18:35 Comment(0)
M
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.

Marplot answered 29/1, 2020 at 9:16 Comment(0)
B
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

Bocock answered 4/9, 2021 at 10:32 Comment(0)
W
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.

Wirer answered 17/8, 2019 at 20:57 Comment(1)
Yes, or use eb deploy --staged to deploy also the uncommitted files.Badenpowell
H
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

Hyaloplasm answered 9/6, 2021 at 18:31 Comment(1)
Can you add your solution as answer and accept it?Colophony
C
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": {
  }
}
Clarey answered 23/11, 2023 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.