Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku can't find package.json during build although I have it

When I push my node app to heroku master I get this log

remote: Building source:
remote:
remote: -----> App not compatible with buildpack: https://codon-
buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
remote:        Node.js: package.json not found in application root

I can't find the reason why this would happen as I clearly have in my root directory. I checked using git ls-files and it appears.

Is it possible that my application root is not the same as my repository root? How would one config that?

like image 315
Joaquim Ferrer Avatar asked Dec 16 '17 19:12

Joaquim Ferrer


People also ask

Does Heroku run npm build?

By default, Heroku runs npm start while starting deployed Node.

How do I run npm on Heroku?

Run the npm install command in your local app directory to install the dependencies that you declared in your package. json file. Start your app locally using the heroku local command, which is installed as part of the Heroku CLI. Your app should now be running on http://localhost:5000/.

Does Heroku support node 18?

js release schedule below, Heroku's currently supported Node. js versions are 14. x , 16. x , and 18.


2 Answers

One common issue is not having added the files to git.

You might be having package.json in your root directory on you device, without adding it to git, heroku can't find it.

Please check status to confirm and add if not added already

git status git add .

then followed by the usual git push heroku master assuming you are on the master branch. Hope this helps.

like image 70
Rahul R Avatar answered Oct 02 '22 00:10

Rahul R


It seems that when I push to heroku master, heroku pushes the main branch of my local repository to heroku instead of the branch I'm currently in. So what I had to do was pushing with:

git push heroku mybranchname:master

so that my branch (not the master) gets pushed

like image 40
Joaquim Ferrer Avatar answered Oct 01 '22 23:10

Joaquim Ferrer