Heroku使用Node.js部署失败

4
我正在尝试将本地文件推送到Heroku,但出现以下错误。我的代码在Github中。请有经验的人帮我解决问题。谢谢。
$ heroku buildpacks:set heroku/nodejs
Buildpack set. Next release on haz will use heroku/nodejs.
Run git push heroku master to create a new release using this buildpack.
$ git push heroku master
Counting objects: 693, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (500/500), done.
Writing objects: 100% (693/693), 63.10 MiB | 2.54 MiB/s, done.
Total 693 (delta 220), reused 639 (delta 171)
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 haz.
remote: 
To https://git.heroku.com/haz.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/haz.git'
$ 

关于package.json

{
  "name": "haz",
  "version": "1.0.0",
  "description": "Hazzir: An Ionic project",
  "private": "true",
  "dependencies": {
    "express": "^4.13.3"    
  },
  "main": "serve.js",
  "scripts": {
    "start": "node serve.js",
    "postinstall": "bower install && grunt build",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "engines": {
      "node": "4.1.2",
      "npm": "3.4.0"
    },

  "keywords": [
    "Haz",
    "product"
  ],
  "author": "Asim Khan",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/asimkh/apps/issues"
  },
  "homepage": "https://github.com/asimkh/apps#readme"
}

我在本地进行了测试,使用express将应用程序运行在5000端口上。

var express = require('express'),
    app = express();

app.use(express.static('www'));

// CORS (Cross-Origin Resource Sharing) headers to support Cross-site HTTP requests
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});

// API Routes
// app.get('/blah', routeHandler);

app.set('port', process.env.PORT || 5000);

app.listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
});
3个回答

4

我看到这里有几个问题:

1)你需要一个 procfile - https://devcenter.heroku.com/articles/getting-started-with-nodejs#define-a-procfile

2)你没有在 package.json 中指定引擎。

"engines": {
  "node": "0.10.x"
},

请看这里- https://discussion.heroku.com/t/the-official-node-js-buildpack-is-going-on-a-diet/100 3) 您已经将node_modules目录提交到git。您应该能够使用npm install下载软件包(这是您的packages.json文件的作用)。
删除此目录,并将其删除提交到git。 然后,创建一个.gitignore文件。在.gitignore文件中添加以下行:
node_modules

将此 .gitignore 文件提交到您的代码库中。
Git 现在将会忽略您的 node_modules_ 目录。

我已经添加了更多细节。 - Alex
我更新了Github仓库,请查看https://github.com/asimkh/apps/tree/haz/,我添加了Procfile、引擎更新和.gitignore。 - Asim Khan
我已经在本地和在线上删除了该目录,但仍然出现错误 ====> 到 https://git.heroku.com/haz.git ![远程拒绝] master -> master(pre-receive hook declined) 错误:无法将某些引用推送到 'https://git.heroku.com/haz.git' - Asim Khan
好的,再次谢谢。将来如果你需要技术或设计支持我会很乐意帮助你。 - Asim Khan
1
我的错误是“推送被拒绝,无法检测到设置的构建包 heroku/nodejs。”文件路径问题可能与此有关,也可能不相关。我的问题其他方面都是一样的。 - Jay Bienvenu
显示剩余5条评论

2
尝试:git add -f package.json 这对我有效。

0

git init 然后重新添加 heroku 远程连接即可

heroku git:remote -a yourappname

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接