简体   繁体   English

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

[英]Why does Heroku fail to detect Node.js buildpack?

I git cloned a Node.js application (the version specified in the package.json being 4.1.2 and 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 克隆了一个 git 应用程序(在package.json中指定的版本是4.1.2而我本地机器的版本是6.2.2 )并尝试 git 推送 8866689.4 it9228 但失败并给出了错误:

Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz未能检测到设置 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 也没有被检测到的可能原因是什么?

This means that a package.json file isn't checked into the root of your git project, so Heroku is detecting that it isn't a Node.js app.这意味着package.json文件没有被检入到你的 git 项目的根目录中,所以 Heroku 检测到它不是一个 Node.js 应用程序。 You can see this locally:你可以在本地看到这个:

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

It's because Heroku thinks you are deploying a Node app.这是因为 Heroku 认为您正在部署一个 Node 应用程序。 But what you are deploying is the public directory of a Node app, not Node code.但是您正在部署的是 Node 应用程序public目录,而不是 Node 代码。

Heroku uses buildpacks to select how the ap is handled. Heroku 使用 buildpacks 来选择 ap 的处理方式。 You want to clear that Node association:您想清除该节点关联:

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

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 的文件,也可能发生这种情况。


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

Check for package.json in master检查 master 中的 package.json

git show master:package.json

If it's available, trying pushing again.如果可用,请再次尝试推送。

git push heroku master

` `

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

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.我最近犯了一个愚蠢的错误,让我意识到这一点:运行“ls -a”表明我的 package.json 和 .git 文件位于同一个根目录中,这是 heroku 的要求。 EXCEPT that the package.json file WAS NOT included in my latest git commit.除了 package.json 文件没有包含在我最新的 git commit 中。 Running "git status" alerted me that package.json was an untracked file.运行“git status”提醒我 package.json 是一个未跟踪的文件。 So I added it, and ta-da, pushing to heroku worked.所以我添加了它,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.如果您收到与 buildpack 相关的错误,请检查您的 GIT COMMIT 在根目录中是否有 package.json 文件。 If this is true, try manually specifying the buildpack with "heroku buildpacks:set heroku/nodejs" (or your desired language).如果这是真的,请尝试使用“heroku buildpacks:set heroku/nodejs”(或您想要的语言)手动指定构建包。 This should resolve most errors related to buildpack detection.这应该可以解决与 buildpack 检测相关的大多数错误。

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 Java:pom.xml

  • Ruby: Gemfile红宝石:Gemfile

  • Node.js: package.json Node.js:package.json

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

  • PHP: composer.json / index.php PHP:composer.json/index.php

You should:你应该:

git add {file}
git commit -am 'added {file} 
git push heroku master

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.我遇到了同样的问题并尝试了一切,最终意识到没有文件会提交,因为它们已经提交并推送到 github 存储库。 So you need to do the following:因此,您需要执行以下操作:

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

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.这对我有用。

I add Pakage.json file, and then我添加 Pakage.json 文件,然后

Remove old git. folder: rm -rf.git删除旧的 git. 文件夹:rm -rf.git

Create new git: git init新建git:git init

Add all project files: git add.添加所有项目文件:git 添加。

Commit: git commit -m “commit name”提交:git commit -m “commit name”

Creat new heroku application: heroku create新建 heroku 申请:heroku create

Push code to master: git push heroku master推码大师:git 推送heroku大师

App successfully deployed on heroku. App 在 heroku 成功部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM