【问题标题】:Using Heroku for a Node web application将 Heroku 用于 Node Web 应用程序
【发布时间】:2016-06-19 09:07:22
【问题描述】:

我正在尝试在 Heroku 上建立一个项目。我浏览了他们的tutorial for Node apps,现在我正在尝试使用我的存储库来处理我的网络应用程序。我已经创建了该项目,它显示在我的 Heroku 仪表板上,但我无法向其推送任何内容。这是我每次收到的信息:

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Using set buildpack heroku/nodejs
remote: 
remote:  !     Push rejected, failed to detect set buildpack heroku/nodejs
remote: More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote: 
remote: Verifying deploy...
remote: 
remote: !   Push rejected to your_web_app.

我已经确定 buildpack 设置为 nodejs。我使用了来自 Heroku 的信息以及 Heroku wrongly detecting my Node app as a Ruby app,但我仍然无法部署。

我也已经进入了 package.json 文件并在“引擎”部分下添加了我的节点版本。为什么我仍然不能部署到 Heroku?

编辑:这是我的 package.json 文件:

{
  "name": "node",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "express": "~4.13.1",
    "jade": "~1.11.0",
    "morgan": "~1.6.1",
    "serve-favicon": "~2.3.0"
  },
  "engines": {
    "node": "5.7.0"
  }
}

【问题讨论】:

  • 你能分享你的 package.json 吗?
  • @ZeeshanHassanMemon 我刚刚发布了它。抱歉回复晚了
  • @ZeeshanHassanMemon 我的 procfile 只有一行:web: node index.js 我是从 Heroku 上的教程中得到的
  • 我明白了,您似乎在您的应用程序中进行了一些更改,例如稍后添加 package.json 或其他导致 heroku buildpack 混淆的内容,heroku buildpacks:clear //将清除 buildpack heroku buildpacks:set heroku/nodejs //将设置正确的 buildpack

标签: node.js heroku web-applications


【解决方案1】:

确保以下几点:

1- 应用在根目录中有一个package.json 文件。

2- 应用的节点版本在package.json 中定义为:

"engines": {
    "node": "4.1.1"
  },

编辑:构建包修复

heroku buildpacks:clear //清除构建包

heroku buildpacks:set heroku/nodejs //为 node.js 应用设置正确的构建包

heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs -a your-app-name

【讨论】:

  • Zeeshan,我确实在根目录中有一个 package.json 文件,我刚刚发布了原始问题中的内容。为什么要将 node 设置为 4.1.1 版本?当我运行node --version 时,我得到了 v5.7.0,这就是为什么我使用它而不是 4.1.1
  • 请尝试更新的答案,让我知道它是否适合您
  • 这成功了!我的 git 远程名称也有一些问题,但我分别解决了这些问题。这些命令正确设置了我的 buildpack。
猜你喜欢
  • 2018-01-25
  • 2020-01-09
  • 2014-12-13
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
  • 1970-01-01
  • 2020-10-16
  • 2018-01-27
相关资源
最近更新 更多