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

问题描述:

我 git 克隆了一个 Node.js 应用程序(package.json 中指定的版本是 4.1.2,我的本地机器的版本是 6.2.2) 并尝试在 Heroku 上 git push.但它无法构建并出现此错误:

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:

未能检测到 set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz

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

现在我将 buildpack 设置为 heroku/nodejs 并收到此消息:

Now I set the buildpack to heroku/nodejs and I get this message:

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.

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

Now when I run git push heroku master, I am again told:

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.

即使我设置了 Node.js 构建包也没有被检测到的可能原因是什么?

What could be the possible reasons for the Node.js buildpack not being detected even if I set it?

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

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. You can see this locally:

git show master:package.json

要修复它,您需要确保项目的根目录中有一个 package.json(其中还有一个 .git 目录),并将其添加到 git 中:

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:

git add package.json
git commit -m 'track package.json'

措辞(未能检测到 set buildpack")可以改进.它可能应该说未能检测到 Node.js 应用程序".当 buildpack 的检测"脚本运行时 (https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect),它会查找 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.