Javascript Heroku:节点应用程序抛出“无法检测到此应用程序的默认语言”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43362014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:51:49  来源:igfitidea点击:

Heroku: "No default language could be detected for this app" error thrown for node app

javascriptnode.jsgitheroku

提问by Manish Giri

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.

我正在学习 NodeJS,我正在学习的课程有几个项目,按部分排列。我将所有项目都放在一个主文件夹下,该文件夹也是一个git 存储库

Each of these subfolders in the main folder is a node project by itself, complete with package.jsonand 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 -

主文件夹中的每个子文件夹本身都是一个节点项目,package.jsonnode_modules. 问题是当我尝试将一个这样的文件夹(todo-api)中的节点应用程序推送到 heroku 时,我收到以下错误 -

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-apisubfolder into a new project all by itself, and this time the push to Heroku works just fine -

我决定自己将todo-api子文件夹重构为一个新项目,这次推送到 Heroku 工作得很好 -

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?

我不明白为什么会出现“无默认语言”错误,尤其是当两个地方的节点应用程序完全相同时。有什么想法吗?

采纳答案by Damien MATHIEU

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/detectcommand of each of those default buildpacks, until one of them returns a 0 exit code.

Heroku 有一组默认的构建包,当它需要检测你的应用程序的语言时使用。
为了进行检测,它会运行bin/detect每个默认构建包的命令,直到其中一个返回 0 退出代码。

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

这是节点 buildpack 的命令
如您所见,它要求 apackage.json位于应用程序的根目录,而不是位于子文件夹中。

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

这是导致构建失败的差异。您需要将您的应用程序放在 git 存储库的根目录下。

回答by Robin Wieruch

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.jsonfile in the root folder of the repository, it cannot detect the language.

就我而言,我没有在根文件夹中设置 Heroku,因为我的 GitHub 存储库被拆分为frontend/backend/文件夹。他们每个人都有一个package.json。由于 Heroku 需要存储库根文件夹中的package.json文件,因此无法检测语言。

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

就我而言,我必须在backend/文件夹中初始化一个辅助 GitHub 存储库。在后端项目作为单独的项目推送到 GitHub 后,git push heroku master工作。

回答by Mahmoud Hboubati

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

就我而言,我有待处理的文件需要提交给 github :)

回答by Walter Clayton

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.

部署时我在与 master 不同的分支上。这就是它不起作用的原因。

enter image description here

在此处输入图片说明

I changed branch to master and it worked.

我将分支更改为 master 并且它起作用了。

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

不要忘记在 package.json 的脚本中放入 "start" : "node app.js"

Otherwise you will get H10 code error. enter image description here

否则你会得到 H10 代码错误。 在此处输入图片说明

The app then worked. enter image description here

该应用程序然后工作。 在此处输入图片说明