Heroku:节点应用程序抛出的错误“没有默认的语言可以检测到这个应用程序”

我正在学习NodeJS,我正在学习的课程有几个项目,按部分安排。 我有一个主文件夹下的所有项目,这也是一个Git仓库 。

主文件夹中的每个子文件夹都是一个节点项目,在node_modules包含package.json和相关的依赖关系。 问题是,当我试图将节点应用程序在一个这样的文件夹( 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' 

这是项目的目录结构 –

在这里输入图像描述

我决定把todo-api子文件夹重新整理到一个新的项目中,而这一次对Heroku的推动工作得很好 –

在这里输入图像描述

我不明白为什么我会得到“没有默认语言”的错误,特别是当两个节点的应用程序完全相同时。 有什么想法吗?

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

这是节点buildpack的命令 。
正如你所看到的,它需要一个package.json位于你的应用程序的根目录,而不是在一个子文件夹中。

这是导致构build失败的差异。 你需要把你的应用程序放在你的git仓库的根目录下。