49

I am learning NodeJS and the course I'm following has several projects, arranged by sections. I have all the projects under one main folder, which is also a git repository.

Each of these subfolders in the main folder is a node project by itself, complete with package.json and related dependencies in node_modules. The problem is when I tried to push the node app in one such folder(todo-api) to heroku, I get the following error -

remote: Compressing source files... done.
remote: Building source:
remote: 
remote:  !     No default language could be detected for this app.
remote:                         HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote:                         See https://devcenter.heroku.com/articles/buildpacks
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to agile-forest-32749.
remote: 
To https://git.heroku.com/agile-forest-32749.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/agile-forest-32749.git'

This is the directory structure for the project -

enter image description here

I decided to refactor out the todo-api subfolder into a new project all by itself, and this time the push to Heroku works just fine -

enter image description here

I don't understand why I get the "no default language" error, especially when the node app is exactly the same in both places. Any thoughts?

Manish Giri
  • 3,562
  • 8
  • 45
  • 81

13 Answers13

39

Heroku has a set of default buildpacks, used when it needs to detect the language of your app.
In order to do that detection, it runs the bin/detect command of each of those default buildpacks, until one of them returns a 0 exit code.

This is the command for the node buildpack.
As you can see, it requires a package.json to be located at the root of your app, not in a subfolder.

This is the difference causing your build to fail. You need to put your app at the root of your git repository.

Damien MATHIEU
  • 31,924
  • 13
  • 86
  • 94
32

In my case, I hadn't Heroku set up in the root folder, because my GitHub repository was split up into frontend/ and backend/ folders. Each of them had a package.json. Since Heroku needs the package.json file in the root folder of the repository, it cannot detect the language.

In my case, I had to initialize a secondary GitHub repository in the backend/ folder. After the backend project was pushed to GitHub as separate project, git push heroku master worked.

Robin Wieruch
  • 14,900
  • 10
  • 82
  • 107
13

In my case I had pending files needs to be committed to github :)

Mahmoud Hboubati
  • 1,007
  • 11
  • 26
  • I was thinking it was just my package.json containing only "{}" but it was because my package.json was not committed. Thanks! – KANJICODER Jul 04 '20 at 12:04
12

In my case I had 2 sub folders in root of my project

  • Client
  • Server

So I want deploy Server folder to Heroku, so instead of moving server content to root of the project(again hectic work), I used below code to resolve this

in the root of your project do this

git subtree push --prefix sub-folder heroku master
ex:- git subtree push --prefix server heroku master

EDITED: add & commit your code before running the above command, otherwise it won't work.

this worked for me.

Happy coding.

ajaykumar mp
  • 487
  • 5
  • 12
  • Could you please elobaret a bit more? Did you write these on the CLI ? Did you write them one by one? Because I got error on CLI for both lines. – Abdulhakim Nov 05 '21 at 11:18
  • Yes, we need to run this on CLI. run the example command "git subtree push --prefix server heroku master", where server is in the root folder. – ajaykumar mp Mar 15 '22 at 18:38
6

I was also facing the same issue. I solved my problem by changing requirement.txt name to requirements.txt so look at 's'.

Exactly requirements.txt name is required for heroku's automatic detection.

Avinash
  • 359
  • 3
  • 5
  • 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 Dec 09 '21 at 09:11
  • same exactly. Thanks! – SmilingKnight Jan 15 '22 at 13:33
5

You need to set a language for the project. Without using the terminal, go to Heroku project. Click on settings, scroll down Build Backbacks and add a language (nodejs, etc).

brockhampton
  • 294
  • 2
  • 8
3

I got the same message

      No default language could be detected for this app.

I was on a different branch than master when deploying. That's why it didn't work.

switch to master

I changed branch to master and it worked.

Don't forget to put "start" : "node app.js" in the scripts of package.json

Otherwise you will get H10 code error.

H10 error

The app then worked.

enter image description here

Walter Clayton
  • 141
  • 2
  • 7
2

In case you have "client"(also called "frontend") and "server"(also called "backend") folder separately, then best method probably would be to move your frontend folder inside backend folder. To do it:

  1. Make sure you have the project folder on your computer and then delete github website repo and heroku website repo.

  2. Delete git files inside your project folder, in other words, ungit your folder.

  3. Grab your frontend folder and place it right inside your backend folder. Frontend folder should be at the same level of the package.json file of the backend folder. After this point your project folder is your backend folder.

  4. open CMD/termial on your project folder and git init on your project folder. You may also want to add a .gitignore file (it should be at the same level with package.json file). Inside .gitignore file type: node_modules

  5. Then, go to github website, create a repo with the same name as your project folder. Then copy github repo url.

  6. Then open CMD on project folder and:

git add .
git commit -m 'any message'
git remote add origin <url>
git push origin master
  1. Go to heroku, create a project and connect your heroku project to github repo. Also allow auto-deployment.

  2. IMPORTANT: open package.json file of the backend folder. As your backend package.json file is at the same level with frontend folder, you will just need to delete one dot:

    "client": "npm run start --prefix ../frontend",

change it to this:

    "client": "npm run start --prefix ./frontend",
  1. To test, make a small change on your project folder, then
git add
git commit -m 'any message'
git push origin master

Check if changes uploaded to github. Then check to see if changes uploaded to heroku successfully.

Abdulhakim
  • 620
  • 8
  • 11
1

This is probably because your package.json and package-lock.json files are in the root directory, and you have two separate folders for client and server.

move those files in the server folder and try "git push heroku master"

It should work

Nahiduzzaman
  • 151
  • 1
  • 4
0

I had the same problem and fixed it by putting my server side files including the package.json in the root folder, then worked.

Ibrahim BHMBS
  • 379
  • 3
  • 6
0

You should make your requirements.txt file correctly. I got this error because I have used (pip freeze > requirements. txt) commands for create the file. but it should be pip freeze > requirements.txt without any spaces.

0

-> Make sure requirements.txt is at the root folder of your project.

-> Make sure you are pushing to right branch

git push heroku your_branch_name_goes_here
K_Mohit
  • 528
  • 3
  • 17
0

in the root folder for Heroku deployment should have index.php so if the root folder contains index.html or some other file with it should be change with index.php then it works for automatic deployment