为什么 Heroku 检测不到 Node.js buildpack?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38658038/
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-09-02 20:27:07  来源:igfitidea点击:

Why does Heroku fail to detect Node.js buildpack?

node.jsgitherokugit-clonebuildpack

提问by Shree

I git cloned a Node.js application (the version specified in the package.jsonbeing 4.1.2and 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:

我GIT克隆了的Node.js应用程序(在指定的版本package.json存在4.1.2和我的本地机器的存在6.2.2),并试图在Heroku混帐推。但它无法构建并出现此错误:

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

无法检测到 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 设置为 heroku/nodejs 并收到以下消息:

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:

现在,当我运行时git push heroku master,我再次被告知:

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?

即使我设置了 Node.js buildpack,也没有检测到它的可能原因是什么?

回答by hunterloftis

This means that a package.jsonfile 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:

这意味着package.json文件没有被检入到你的 git 项目的根目录中,所以 Heroku 检测到它不是一个 Node.js 应用程序。你可以在本地看到这个:

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:

要修复它,您需要确保项目的根目录中有一个 package.json(其中还有一个 .git 目录),并将其添加到 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.

措辞(“未能检测到 set buildpack”)可以改进。它可能应该说“未能检测到 Node.js 应用程序”。当 buildpack 的“检测”脚本运行时 ( https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect),它会查找 package.json 文件以验证是否存在节点应用程序可供建造。

回答by Scott

It's because Heroku thinks you are deploying a Node app. But what you are deploying is the publicdirectoryof a Node app, not Node code.

这是因为 Heroku 认为您正在部署一个 Node 应用程序。但是您部署的是Node 应用程序public目录,而不是 Node 代码。

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

Heroku 使用 buildpacks 来选择 ap 的处理方式。您想清除该节点关联:

buildpacks:clear # clear all buildpacks set on the app

buildpacks:clear # clear all buildpacks set on the app

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

这意味着“下一个版本将正常检测 buildpack。”,这应该会为您解决。

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

参考:https: //devcenter.heroku.com/articles/buildpacks

回答by Pandurang Yachwad

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.

如果您删除或重命名之前导致自动检测应用程序类型并因此自动设置应用程序上检测到的 buildpack 的文件,也可能发生这种情况。



回答by Del_sama

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

如果你在一个分支上工作,你需要设置 master 来跟踪你的分支

git branch -f --track master origin/branch_name

git branch -f --track master origin/branch_name

Check for package.json in master

检查 master 中的 package.json

git show master:package.json

git show master:package.json

If it's available, trying pushing again.

如果可用,请再次尝试推送。

git push heroku master

git push heroku master

`

`

回答by Aaron Chamberlain

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

对其他答案的一些微小说明:错误“无法检测到 set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz”或任何类似内容,表示您正在尝试的 GIT COMMIT推送到 heroku 没有被检测为 node.js 应用程序。(注意细微之处的大写)。

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.

我最近犯了一个愚蠢的错误,让我意识到这一点:运行“ls -a”表明我的 package.json 和 .git 文件位于同一个根目录中,这是 heroku 的要求。除了 package.json 文件没有包含在我最新的 git commit 中。运行“git status”提醒我 package.json 是一个未跟踪的文件。所以我添加了它,ta-da,推送到 heroku 工作。

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.

如果您收到与 buildpack 相关的错误,请检查您的 GIT COMMIT 在根目录中是否有 package.json 文件。如果这是真的,请尝试使用“heroku buildpacks:set heroku/nodejs”(或您想要的语言)手动指定构建包。这应该可以解决与 buildpack 检测相关的大多数错误。

回答by Akash Kandpal

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:

大多数应用程序至少存在这些签名中的一个,因此如果您看到此错误,通常意味着一个重要文件未签入您的 git 存储库:

  • Java: pom.xml

  • Ruby: Gemfile

  • Node.js: package.json

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

  • PHP: composer.json / index.php

  • Java:pom.xml

  • 红宝石: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

回答by GeorgeS

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:

我遇到了同样的问题并尝试了一切,最终意识到没有文件会提交,因为它们已经提交并推送到 github 存储库。因此,您需要执行以下操作:

  • Remove old git. folder:
  • 删除旧的 git。文件夹:

rm -rf .git

rm -rf .git

  • Create new git:
  • 创建新的git:

git init

混帐初始化

  • Add all project files:
  • 添加所有项目文件:

git add .

git 添加。

  • Commit:
  • 犯罪:

git commit -m “commit name”

git commit -m “提交名称”

  • Creat new heroku application:
  • 创建新的 heroku 应用程序:

heroku create

heroku 创建

  • Push code to master:
  • 推送代码到master:

git push heroku master

git push heroku master

This worked for me.

这对我有用。