30

I git cloned a Node.js application (the version specified in the package.json being 4.1.2 and that of my local machine being 6.2.2) and tried to git push on Heroku. But it failed to build and gave this error:

Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz

Now I set the buildpack to heroku/nodejs and I get this message:

Buildpack set. Next release on lit-badlands-92088 will use heroku/nodejs.
Run git push heroku master to create a new release using this buildpack.

Now when I run git push heroku master, I am again told:

remote: -----> Failed to detect set buildpack
        https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz  

remote: More info: 
https://devcenter.heroku.com/articles/buildpacks#detection-failure  

remote:  
remote:  !     Push failed  
remote: Verifying deploy...  
remote:  
remote: !       Push rejected to lit-badlands-92088.

What could be the possible reasons for the Node.js buildpack not being detected even if I set it?

hong4rc
  • 3,999
  • 4
  • 21
  • 40
Shree
  • 533
  • 1
  • 5
  • 10
  • Does this answer your question? [Heroku: "No default language could be detected for this app" error thrown for node app](https://stackoverflow.com/questions/43362014/heroku-no-default-language-could-be-detected-for-this-app-error-thrown-for-no) – user202729 Aug 19 '21 at 01:40

8 Answers8

39

This means that a package.json file isn't checked into the root of your git project, so Heroku is detecting that it isn't a Node.js app. You can see this locally:

git show master:package.json

To fix it, you'll want to be sure there is a package.json in the root of your project (where there is also a .git directory), and add it to git:

git add package.json
git commit -m 'track package.json'

The phrasing ('failed to detect set buildpack') could be improved. It should probably say 'failed to detect Node.js app'. When the buildpack's "detect" script is run (https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect), it looks for a package.json file to verify that there's a node app available to build.

hunterloftis
  • 13,386
  • 5
  • 48
  • 50
  • I'm having the same issue, and the package.json exists in my repo. Do you know what could possibly be another cause for this error? – katie Jul 31 '16 at 01:57
  • 1
    So package.json needs to be in the folder that has .git?In my root directory,I have .git and a folder named node and in node folder,I have index.js and package.json. – Shree Jul 31 '16 at 07:30
  • 1
    Is this due to the fact that package.json is in the subdirectory rather than the root dir of the git repo?Should I try moving package.json to the root dir? – Shree Jul 31 '16 at 07:37
  • 2
    Yes - package.json must be in the root directory of the project. – hunterloftis Aug 01 '16 at 00:48
  • Just another query...is it okay if index.js and package.json are not in the same directory? – Shree Aug 01 '16 at 03:11
  • index.js isn't anything special in node (unlike php). Your node app can start whatever process it likes: https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type – hunterloftis Aug 01 '16 at 16:44
  • 1
    @huterloftis correct. I would also add that developers working in a subdirectory must copy their `package.json` from subdirectory to root folder where there's a `.git` folder or move the whole app from subdirectory to root folder and then init a git in this root. This would help in case devs are trying to deploy app with heroku: `git push heroku master` – Junior Mayhé Jul 31 '17 at 17:51
10

It’s because Heroku thinks you are deploying a Node app. But what you are deploying is the public directory of a Node app, not Node code.

Heroku uses buildpacks to select how the app is handled. You want to clear that Node association:

heroku buildpacks:clear # clear all buildpacks set on the app

Which means that “Next release will detect buildpack normally.”, that should solve it for you.

ref: https://devcenter.heroku.com/articles/buildpacks

Onen simon
  • 750
  • 1
  • 13
  • 17
Scott
  • 4,211
  • 3
  • 17
  • 20
6

I had similar issue, here are the steps which solved the problem.

heroku buildpacks:set heroku/nodejs
git push heroku master

Basically details are in the more info link -


This situation may also occur if you remove or rename a file that previously led to the automatic detection of your application type and thus the automatic setting of the detected buildpack on your application.


Pandurang Yachwad
  • 1,695
  • 1
  • 19
  • 29
4

If you are working on a branch, you need to set master to track your branch

git branch -f --track master origin/branch_name

Check for package.json in master

git show master:package.json

If it's available, trying pushing again.

git push heroku master

`

Del_sama
  • 61
  • 3
2

Some tiny clarifications on other answers: The error "Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz" or anything similar, means to say the GIT COMMIT you are trying to push to heroku was not DETECTED as a node.js app. (Note the capitals for subtleties).

I recently made a stupid mistake that made me aware of this: Running "ls -a" showed that my package.json and .git files were in the same root directory, as required by heroku. EXCEPT that the package.json file WAS NOT included in my latest git commit. Running "git status" alerted me that package.json was an untracked file. So I added it, and ta-da, pushing to heroku worked.

If you get an error related to buildpack, check that your GIT COMMIT has a package.json file in the root directory. If this is true, try manually specifying the buildpack with "heroku buildpacks:set heroku/nodejs" (or your desired language). This should resolve most errors related to buildpack detection.

Aaron Chamberlain
  • 653
  • 2
  • 10
  • 26
1

Most apps have at least one of these signatures present, so if you see this error, it usually means an important file isn't checked into your git repository:

  • Java: pom.xml

  • Ruby: Gemfile

  • Node.js: package.json

  • Python: requirements.txt / setup.py / Pipfile

  • PHP: composer.json / index.php

You should:

git add {file}
git commit -am 'added {file} 
git push heroku master
Maciej Jureczko
  • 1,560
  • 6
  • 19
  • 23
Akash Kandpal
  • 3,126
  • 28
  • 25
1

I run into the same issue and tried everything, eventually realized no file would commit because they were already committed and pushed to the github repository. So you need to do the following:

  • Remove old git. folder:

rm -rf .git

  • Create new git:

git init

  • Add all project files:

git add .

  • Commit:

git commit -m “commit name”

  • Creat new heroku application:

heroku create

  • Push code to master:

git push heroku master

This worked for me.

GeorgeS
  • 107
  • 9
0

I add Pakage.json file, and then

Remove old git. folder: rm -rf .git

Create new git: git init

Add all project files: git add .

Commit: git commit -m “commit name”

Creat new heroku application: heroku create

Push code to master: git push heroku master

App successfully deployed on heroku.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 01 '21 at 08:28