【问题标题】:heroku deploy failed using nodejsheroku 使用 nodejs 部署失败
【发布时间】:2016-02-20 02:23:43
【问题描述】:

我正在尝试将本地文件推送到 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'));
});

【问题讨论】:

    标签: node.js express heroku npm ionic


    【解决方案1】:

    git init 然后读取 heroku 远程工作

    heroku git:remote -a yourappname
    

    【讨论】:

      【解决方案2】:

      试试:git add -f package.json 它对我有用。

      【讨论】:

        【解决方案3】:

        我在这里看到了一些问题

        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_ 目录

        【讨论】:

        • 我添加了更多细节
        • 我更新了github resp,检查github.com/asimkh/apps/tree/haz,我添加了procfile,引擎更新和gitignore
        • 您的 node_modules 目录仍在存储库中。你需要删除它
        • 我在本地和在线删除了目录,但仍然出现错误 ====> To git.heroku.com/haz.git ! [remote denied] master -> master (pre-receive hook denied) 错误:未能将一些 refs 推送到 'git.heroku.com/haz.git'
        • 我的错误是“推送被拒绝,未能检测到 set buildpack heroku/nodejs。”文件路径问题是一种可能相关也可能不相关的症状。我的问题的其他一切都是一样的。
        猜你喜欢
        • 2019-02-16
        • 1970-01-01
        • 2018-08-21
        • 2019-03-05
        • 2019-12-02
        • 2013-04-08
        相关资源
        最近更新 更多