Heroku node.js应用程序在本地运行但远程崩溃

时间:2016-12-22 06:35:10

标签: node.js heroku

我有一个node.js应用程序不是Web应用程序。 这是我的package.json

{
  "name": "myapp-backend",
  "version": "1.0.0",
  "description": "MyApp PubNub backend",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://git.heroku.com/myapp.git"
  },
  "keywords": [
    "backend"
  ],
  "author": "Pete Gu",
  "license": "ISC",
  "dependencies": {
    "pubnub": "^4.3.3"
  },
  "engines": {
    "node" : "6.9.2"
  }
}

Procfile的内容:

app: node app.js

我运行heroku local时会运行。但是,在推送代码并使用heroku logs检查日志后,我看到了这一点:

2016-12-22T06:07:01.276053+00:00 app[api]: Deploy fb193d3 by user xxxxx@xxxx.com
2016-12-22T06:07:01.477131+00:00 heroku[slug-compiler]: Slug compilation started
2016-12-22T06:07:01.477136+00:00 heroku[slug-compiler]: Slug compilation finished
2016-12-22T06:07:01.276053+00:00 app[api]: Release v13 created by user gpeetonn@gmail.com
2016-12-22T06:07:01.507095+00:00 heroku[web.1]: State changed from crashed to starting
2016-12-22T06:07:02.759643+00:00 heroku[web.1]: Starting process with command `npm start`
2016-12-22T06:07:06.003266+00:00 heroku[web.1]: Process exited with status 1
2016-12-22T06:07:06.016232+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-22T06:07:06.017114+00:00 heroku[web.1]: State changed from crashed to starting
2016-12-22T06:07:05.872484+00:00 app[web.1]: npm ERR! Linux 3.13.0-105-generic
2016-12-22T06:07:05.872909+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-12-22T06:07:05.873173+00:00 app[web.1]: npm ERR! node v6.9.2
2016-12-22T06:07:05.873421+00:00 app[web.1]: npm ERR! npm  v3.10.9
2016-12-22T06:07:05.877486+00:00 app[web.1]: npm ERR! missing script: start
2016-12-22T06:07:05.875800+00:00 app[web.1]: 
2016-12-22T06:07:05.877738+00:00 app[web.1]: npm ERR! 
2016-12-22T06:07:05.877884+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-12-22T06:07:05.878031+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-12-22T06:07:05.892349+00:00 app[web.1]: 
2016-12-22T06:07:05.892997+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-12-22T06:07:05.892655+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-12-22T06:07:07.532860+00:00 heroku[web.1]: Starting process with command `npm start`
2016-12-22T06:07:10.603753+00:00 app[web.1]: npm ERR! Linux 3.13.0-105-generic
2016-12-22T06:07:10.604065+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-12-22T06:07:10.604260+00:00 app[web.1]: npm ERR! node v6.9.2
2016-12-22T06:07:10.604476+00:00 app[web.1]: npm ERR! npm  v3.10.9
2016-12-22T06:07:10.606525+00:00 app[web.1]: 
2016-12-22T06:07:10.607621+00:00 app[web.1]: npm ERR! missing script: start
2016-12-22T06:07:10.607822+00:00 app[web.1]: npm ERR! 
2016-12-22T06:07:10.607900+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-12-22T06:07:10.607998+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-12-22T06:07:10.618207+00:00 app[web.1]: 
2016-12-22T06:07:10.618415+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-12-22T06:07:10.618645+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-12-22T06:07:10.718608+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-22T06:07:10.710362+00:00 heroku[web.1]: Process exited with status 1

...这对我来说完全没有意义 - 为什么heroku尝试使用npm start而不是阅读Procfile启动应用?

2 个答案:

答案 0 :(得分:0)

Heroku似乎正在尝试启动web dyno,似乎并不知道你的Procfile。

您确定已将Procfile添加到git仓库吗?

无论如何,试试这个:

heroku ps:scale web=0
heroku ps:scale app=1

您还可以在package.json的“scripts”部分添加“start”:“node app.js”。

答案 1 :(得分:0)

我可以看到错误缺少脚本:开始所以你需要添加

"scripts": {
"start": "node bin/xxx" //your main file name
}

将此添加到package.json。