Heroku错误部署app:无法解析package.json

时间:2016-12-21 19:56:49

标签: node.js git heroku package.json

我是Heroku的新手,我一直在尝试使用node.js部署Hello World应用。

问题是我有这个

error: failed to push some refs to 'https://git.heroku.com/sebasaenz.git'

但我真的不知道如何解决问题。通过以前的错误消息,它似乎与package.json文件有关,但我试图在文档中找到可能存在的问题,我真的不明白它是什么。

输入git push heroku master

后出现错误消息
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 920 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote: parse error: Expected another key-value pair at line 14, column 3
remote:  !     Unable to parse package.json
remote: 
remote: 
remote: -----> Build failed
remote:        
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:        
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:        
remote:        Love,
remote:        Heroku
remote:        
remote:  !     Push rejected, failed to compile Node.js app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to sebasaenz.
remote: 
To https://git.heroku.com/sebasaenz.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/sebasaenz.git'

我的package.json文件如下:

{
  "name": "hello-world",
  "version": "1.0",
  "description": "Node demo",
  "engines": {
    "node": "5.9.1"
  },
  "main": "index.js",
    "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "ejs": "2.4.1" 
  }, //this is line 14 
  "repository": {
    "type": "git",
    "url": "https://git.heroku.com/sebasaenz.git"
  },
  "keywords": [
    "node",
    "heroku"
  ],
  "license": "MIT"
}

我已经找过具有相似特征的帖子,但我找不到任何可以帮助我的内容。

3 个答案:

答案 0 :(得分:0)

您提供的JSON中唯一无效的位是依赖项中"ejs": "2.4.1"和关键字数组中"heroku"之后的逗号。

答案 1 :(得分:0)

我遇到了同样的问题。请注意来自heroku的这两行:

remote: parse error: Expected another key-value pair at line 14, column 3
remote:  !     Unable to parse package.json

package.json文件有问题。就我而言,我错过了一个括号,最后关闭了文件。请参阅以下示例:

{
  "name": "tempdeployment",

  "version": "1.0.0",
  "description": "This version of __ is for temporary deployment.",
  "main": "app.js",
  "scripts": {
    "test": "test.js",
    "start": "node app.js"
  },
  "author": "____",
  "license": "ISC",
  "dependencies": {
    "ejs": "^2.5.7",
    "express": "^4.16.2",
    "request": "^2.83.0"
  },
  "engines": {
    "node":"^8.9.4"
  }

请注意,此JSON文件缺少右括号。一旦我添加了括号,我就没有遇到任何问题。在您的情况下,看起来第14行的某个键值对存在问题。修复此问题,您的应用应该没有问题进行部署。

以下是我的package.json文件的更正版本:

{
  "name": "tempdeployment",

  "version": "1.0.0",
  "description": "This version of __ is for temporary deployment.",
  "main": "app.js",
  "scripts": {
    "test": "test.js",
    "start": "node app.js"
  },
  "author": "____",
  "license": "ISC",
  "dependencies": {
    "ejs": "^2.5.7",
    "express": "^4.16.2",
    "request": "^2.83.0"
  },
  "engines": {
    "node":"^8.9.4"
  }
}

答案 2 :(得分:-1)

mvn clean install

然后推送到heroku master。