我正在学习 NodeJS,我正在学习的类(class)有几个项目,按部分排列。我将所有项目都放在一个主文件夹下,这也是一个 git repository .
主文件夹中的每个子文件夹本身就是一个 Node 项目,包含 package.json
和 node_modules
中的相关依赖项。问题是当我试图将一个这样的文件夹(todo-api
)中的 Node 应用程序推送到 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 工作正常 -
我不明白为什么会出现“无默认语言”错误,尤其是当两个地方的 Node 应用程序完全相同时。有什么想法吗?
最佳答案
Heroku 有一组默认的构建包,当它需要检测您的应用程序的语言时使用。
为了进行检测,它运行每个默认构建包的 bin/detect
命令,直到其中一个返回 0 退出代码。
This is the command for the node buildpack .
如您所见,它需要一个 package.json
位于应用程序的根目录中,而不是子文件夹中。
这是导致构建失败的差异。您需要将您的应用放在 git 存储库的根目录下。
关于javascript - Heroku: Node 应用程序抛出 "No default language could be detected for this app"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43362014/