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 - node.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.

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

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.

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.

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.

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

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.

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

Related

Nest.js error with ENOENT: no such file or directory, open './push-service-account.json'

I tried to find a solution to the problem, I don’t think that the option to remove package-lock.json is suitable for me, since I install dependencies from it using npm ci.
In project i have Node: 12.22.12
npm: 6.14.16
enter image description here
Looks like in your PushService you are trying to read ./push-service-account.json. This may look fine in your src directory, but when you compile, Typescript won't move the json file for you. You either need to use a post-build step that moves all .json files you plan to read to the relative dist location, or you should put all of these .json files in a common directory relative to your project root so that you can use fs.readFile(path.join(process.cwd(), 'common', fileName))

Uploading a reactjs code in github, without the node_modules folder

I want to upload a react app in github. But, I dont want to HOST IT. I only want to keep the codes there. But while uploading, I had problem with uploading the node_modules folder. I searched other repo, and even there node_modules folder wasn't present. Still their code could be used by running a command called npm install or something similar to that.
What are the steps to upload My ReactJS Code without uploading the node_modules. But in such a way, by which anyone can install all the node modules by npm install or something similar to that?
To tell git to exclude something in your project, you use a .gitignore file. In the .gitignore file, you can add patterns to files or folders and git will not track any of those files.
Here is a template for Node projects given by GitHub. It excludes the node_modules folder. Put it in your project root and remember to rename it to just .gitignore (note the period in front).

How to create new angular app without downloading node_modules files

I'm new in angular and every time I want to create new angular application it downloads approximately 316MB files from internet.
I was wondering if there is any way to skip downloading node_modules folder and just download other angular files neccessary to run my app and then copy&paste my (existing) node_modules folder to root folder of my app.
you can run the command ng new <YourProjectName> --skip-install, It will create a package without node_modules folder.
Yes, it's possible. Copy package.json, package-lock.json and node_modules. node_modules usually doesn't contain any project specific files or configurations.

Deploying next app to Azure fails because node_modules need to be re-installed

I'm creating a build in Azure pipelines and copying node_modules as well as 'out' folder, package.json, package-lock.json, next.config.js and .next folder. I copy all of these into an artifact directory.
I then zip this as an artifact and then do a zip deploy to Azure App Service Linux Web app.
However running npm start (which just points to next start in the package.json) doesn't work as it complains about next not being found in node_modules (even though its there)
What do I need to do to get it work?
If I download the zip file and unzip it locally, it doesn't work either even though all the node_modules are there. I need to run npm ci to be able to get next start to work. How come?
Aren't I meant to just be able to copy node_modules across and everything should just work?
Also bonus points - do I need to force next to start on port 8080 on azure? The default port 3000 doesn't seem to work?
And Azure docs say that npm install is run when package.json is detected. However that's clearly not happening either.
Any help and insights would be most appreciated!
If anyone is trying to deploy Next.js SSR apps to Azure Web apps, the issue is the copying of the node_modules and the config of next.config.js
I was using the File Copy task in my yml file. This isn't good enough.
You have to use cp -paR node_modules to your artifact folder.
We don't have a server.js file but you can't use serverless unless you create a server.js file :) So I changed the next.config.js to server and then it all works without a server.js file.

How to correctly setup folders / files in nodejs?

I am currently starting out in node.js and I am a bit confused with the folder/file setups. Let´s say I have a main folder where all my different projects are located, and those are folders too. Now where do I need to keep my node-modules folder? Also how about the package.json file, do I need that inside each project folder?
use npm init first
it will make a package.json file.
Install the dependencies which be stored in Node_modules folder
Now make a folder named Public
with subfolders assets, css, js, index.html -- the FrontEnd part

Resources