【问题标题】:Application Error Heroku - Problems with Deployment应用程序错误 Heroku - 部署问题
【发布时间】:2015-02-25 20:35:35
【问题描述】:

试图弄清楚如何将我的应用程序推送到 Heroku。我刚刚成功完成了他们的 Node.js 教程,我可以通过 npm install 和 foreman start 在本地运行我的应用程序就好了,但是当我尝试推送它并在 Heruko 网站上打开它时出现错误,我假设我需要安装一些东西,但我不能很好地破译日志。

这是我的日志。 (Git、NodeJS 和 Heruko 的新手,仅供参考,如果我遗漏了一些明显的东西,非常抱歉)

$ heroku logs --tail
←[36m2014-12-29T15:38:08.188615+00:00 app[web.1]:←[0m npm ERR! There is likely additional logging output above.
←[36m2014-12-29T15:38:08.188812+00:00 app[web.1]:←[0m npm ERR! System Linux 3.8.11-ec2
←[36m2014-12-29T15:38:08.897061+00:00 heroku[web.1]:←[0m Process exited with status 1
←[36m2014-12-29T15:38:08.916161+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[33m2014-12-29T15:38:29.680490+00:00 heroku[api]:←[0m Scale to web=1 by myEmail.com
←[32m2014-12-29T15:38:36.597146+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=36191235-65e4-441e-9cfa-9498182d1834 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T15:38:36.810592+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=10f03d06-42d1-4119-999a-8337a8651222 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T15:38:40.082568+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=86f49b1b-d70f-444c-9927-4695b6b34e89 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T15:38:40.354619+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=38a9fb83-f441-4752-a1e9-e271db850383 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T15:38:43.300739+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=d579a34f-fb80-4cae-b33e-aa80f3850a69 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T15:38:43.574003+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=91f015a4-ee68-4e2e-b40f-49e47fbf0d99 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[33m2014-12-29T16:03:09.011875+00:00 heroku[api]:←[0m Scale to web=1 by myEmail.com
←[32m2014-12-29T16:03:15.311197+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=c6f7e40a-c7ac-4d68-9aa7-f3341a6cc098 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T16:03:15.594058+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=18a62541-e33a-4781-be06-045abe145879 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[33m2014-12-29T16:09:16.117810+00:00 heroku[api]:←[0m Release v4 created by myEmail.com
←[33m2014-12-29T16:09:16.117779+00:00 heroku[api]:←[0m Deploy c90771b by myEmail.com
←[36m2014-12-29T16:09:16.683226+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2014-12-29T16:09:18.193386+00:00 heroku[web.1]:←[0m Starting process with command `node server/app.js`
←[36m2014-12-29T16:09:19.314638+00:00 app[web.1]:←[0m module.js:340
←[36m2014-12-29T16:09:19.316610+00:00 app[web.1]:←[0m at Function.Module._load (module.js:280:25)
←[36m2014-12-29T16:09:19.316611+00:00 app[web.1]:←[0m at Module.require (module.js:364:17)
←[36m2014-12-29T16:09:19.316613+00:00 app[web.1]:←[0m at require (module.js:380:17)
←[36m2014-12-29T16:09:19.316615+00:00 app[web.1]:←[0m at module.exports (/app/server/config/express.js:38:13)
←[36m2014-12-29T16:09:19.316617+00:00 app[web.1]:←[0m at Object.<anonymous> (/app/server/app.js:15:28)
←[36m2014-12-29T16:09:19.314316+00:00 app[web.1]:←[0m
←[36m2014-12-29T16:09:19.314898+00:00 app[web.1]:←[0m throw err;
←[36m2014-12-29T16:09:19.314906+00:00 app[web.1]:←[0m           ^
←[36m2014-12-29T16:09:19.316618+00:00 app[web.1]:←[0m at Module._compile (module.js:456:26)
←[36m2014-12-29T16:09:19.316620+00:00 app[web.1]:←[0m at Object.Module._extensions..js (module.js:474:10)
←[36m2014-12-29T16:09:19.316621+00:00 app[web.1]:←[0m at Module.load (module.js:356:32)
←[36m2014-12-29T16:09:19.316608+00:00 app[web.1]:←[0m at Function.Module._resolveFilename (module.js:338:15)
←[36m2014-12-29T16:09:19.316605+00:00 app[web.1]:←[0m Error: Cannot find module 'connect-livereload'
←[36m2014-12-29T16:09:19.316623+00:00 app[web.1]:←[0m at Function.Module._load (module.js:312:12)
←[36m2014-12-29T16:09:20.357443+00:00 heroku[web.1]:←[0m Process exited with status 8
←[36m2014-12-29T16:09:20.375389+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2014-12-29T16:09:20.374306+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[36m2014-12-29T16:09:22.796156+00:00 heroku[web.1]:←[0m Starting process with command `node server/app.js`
←[36m2014-12-29T16:09:23.802405+00:00 app[web.1]:←[0m
←[36m2014-12-29T16:09:23.803009+00:00 app[web.1]:←[0m throw err;
←[36m2014-12-29T16:09:23.803010+00:00 app[web.1]:←[0m           ^
←[36m2014-12-29T16:09:23.804497+00:00 app[web.1]:←[0m Error: Cannot find module 'connect-livereload'
←[36m2014-12-29T16:09:23.803003+00:00 app[web.1]:←[0m module.js:340
←[36m2014-12-29T16:09:23.804500+00:00 app[web.1]:←[0m at Function.Module._resolveFilename (module.js:338:15)
←[36m2014-12-29T16:09:23.804501+00:00 app[web.1]:←[0m at Function.Module._load (module.js:280:25)
←[36m2014-12-29T16:09:23.804504+00:00 app[web.1]:←[0m at require (module.js:380:17)
←[36m2014-12-29T16:09:23.804503+00:00 app[web.1]:←[0m at Module.require (module.js:364:17)
←[36m2014-12-29T16:09:23.804507+00:00 app[web.1]:←[0m at Object.<anonymous> (/app/server/app.js:15:28)
←[36m2014-12-29T16:09:23.804508+00:00 app[web.1]:←[0m at Module._compile (module.js:456:26)
←[36m2014-12-29T16:09:23.804509+00:00 app[web.1]:←[0m at Object.Module._extensions..js (module.js:474:10)
←[36m2014-12-29T16:09:23.804512+00:00 app[web.1]:←[0m at Function.Module._load (module.js:312:12)
←[36m2014-12-29T16:09:23.804511+00:00 app[web.1]:←[0m at Module.load (module.js:356:32)
←[36m2014-12-29T16:09:23.804506+00:00 app[web.1]:←[0m at module.exports (/app/server/config/express.js:38:13)
←[36m2014-12-29T16:09:24.510417+00:00 heroku[web.1]:←[0m Process exited with status 8
←[36m2014-12-29T16:09:24.535039+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[32m2014-12-29T16:09:25.516484+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=435a24d0-3242-439b-9646-f9a754d0a0f1 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T16:09:25.835724+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=b0ea9325-dbc1-4001-b0d3-fc228043bf55 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[33m2014-12-29T16:11:13.788307+00:00 heroku[api]:←[0m Scale to web=1 by myEmail.com
←[32m2014-12-29T16:23:05.892581+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=3965fe7b-4155-49cf-81c8-56e20fe10ce3 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T16:23:06.183875+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=abdfb4e3-fc6c-4a18-85d0-4fb1653e0040 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[33m2014-12-29T16:24:17.858493+00:00 heroku[api]:←[0m Deploy 461491a by myEmail.com
←[33m2014-12-29T16:24:17.858493+00:00 heroku[api]:←[0m Release v5 created by myEmail.com
←[36m2014-12-29T16:24:17.984165+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2014-12-29T16:24:20.032515+00:00 heroku[web.1]:←[0m Starting process with command `node server/app.js`
←[36m2014-12-29T16:24:21.011870+00:00 app[web.1]:←[0m module.js:340
←[36m2014-12-29T16:24:21.012416+00:00 app[web.1]:←[0m           ^
←[36m2014-12-29T16:24:21.014369+00:00 app[web.1]:←[0m Error: Cannot find module 'connect-livereload'
←[36m2014-12-29T16:24:21.012169+00:00 app[web.1]:←[0m throw err;
←[36m2014-12-29T16:24:21.014372+00:00 app[web.1]:←[0m at Function.Module._resolveFilename (module.js:338:15)
←[36m2014-12-29T16:24:21.014375+00:00 app[web.1]:←[0m at Module.require (module.js:364:17)
←[36m2014-12-29T16:24:21.011468+00:00 app[web.1]:←[0m
←[36m2014-12-29T16:24:21.014382+00:00 app[web.1]:←[0m at Module._compile (module.js:456:26)
←[36m2014-12-29T16:24:21.014383+00:00 app[web.1]:←[0m at Object.Module._extensions..js (module.js:474:10)
←[36m2014-12-29T16:24:21.014385+00:00 app[web.1]:←[0m at Module.load (module.js:356:32)
←[36m2014-12-29T16:24:21.014386+00:00 app[web.1]:←[0m at Function.Module._load (module.js:312:12)
←[36m2014-12-29T16:24:21.014377+00:00 app[web.1]:←[0m at require (module.js:380:17)
←[36m2014-12-29T16:24:21.014374+00:00 app[web.1]:←[0m at Function.Module._load (module.js:280:25)
←[36m2014-12-29T16:24:21.014379+00:00 app[web.1]:←[0m at module.exports (/app/server/config/express.js:38:13)
←[36m2014-12-29T16:24:21.014380+00:00 app[web.1]:←[0m at Object.<anonymous> (/app/server/app.js:15:28)
←[36m2014-12-29T16:24:21.799791+00:00 heroku[web.1]:←[0m Process exited with status 8
←[36m2014-12-29T16:24:21.808150+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[36m2014-12-29T16:24:21.808844+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2014-12-29T16:24:23.672321+00:00 heroku[web.1]:←[0m Starting process with command `node server/app.js`
←[36m2014-12-29T16:24:24.673230+00:00 app[web.1]:←[0m
←[36m2014-12-29T16:24:24.675428+00:00 app[web.1]:←[0m at Function.Module._resolveFilename (module.js:338:15)
←[36m2014-12-29T16:24:24.675431+00:00 app[web.1]:←[0m at Module.require (module.js:364:17)
←[36m2014-12-29T16:24:24.675436+00:00 app[web.1]:←[0m at module.exports (/app/server/config/express.js:38:13)
←[36m2014-12-29T16:24:24.673540+00:00 app[web.1]:←[0m module.js:340
←[36m2014-12-29T16:24:24.673797+00:00 app[web.1]:←[0m throw err;
←[36m2014-12-29T16:24:24.673804+00:00 app[web.1]:←[0m           ^
←[36m2014-12-29T16:24:24.675438+00:00 app[web.1]:←[0m at Object.<anonymous> (/app/server/app.js:15:28)
←[36m2014-12-29T16:24:24.675424+00:00 app[web.1]:←[0m Error: Cannot find module 'connect-livereload'
←[36m2014-12-29T16:24:24.675429+00:00 app[web.1]:←[0m at Function.Module._load (module.js:280:25)
←[36m2014-12-29T16:24:24.675443+00:00 app[web.1]:←[0m at Object.Module._extensions..js (module.js:474:10)
←[36m2014-12-29T16:24:24.675445+00:00 app[web.1]:←[0m at Module.load (module.js:356:32)
←[36m2014-12-29T16:24:24.675434+00:00 app[web.1]:←[0m at require (module.js:380:17)
←[36m2014-12-29T16:24:24.675441+00:00 app[web.1]:←[0m at Module._compile (module.js:456:26)
←[36m2014-12-29T16:24:24.675447+00:00 app[web.1]:←[0m at Function.Module._load (module.js:312:12)
←[36m2014-12-29T16:24:25.500954+00:00 heroku[web.1]:←[0m Process exited with status 8
←[36m2014-12-29T16:24:25.515899+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[32m2014-12-29T16:24:26.941578+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=still-anchorage-3610.herokuapp.com request_id=b2c83aaa-778d-4334-8168-df88891294dd fwd="64.255.74.231" dyno= connect= service= status=503 bytes=
←[32m2014-12-29T16:24:27.226106+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-anchorage-3610.herokuapp.com request_id=4ffb26a0-d806-436b-8bf1-703cc39e17b7 fwd="64.255.74.231" dyno= connect= service= status=503 bytes=

【问题讨论】:

  • 你的 package.json 放置正确了吗?请记住,这是应用程序宣言,因此为了部署应用程序,应使用应用程序所需的所有依赖项对其进行更新。
  • 我想是的,如果package.json 不正确,它就不会在本地运行/工作,对吧?
  • 视情况而定。如果您通过运行 npm install 自行安装依赖项,但您没有设置 --save 选项,那么您在本地安装了一些东西,并且在 manifesto 上安装了不同的东西。似乎是您遇到的问题

标签: node.js git heroku


【解决方案1】:

您的应用程序似乎无法加载 connect-livereload 模块。您应该只在本地开发环境中使用它。你可能有这样的代码:

app.use(require('connect-livereload')());

在您的app.js 第 15 行附近。您需要确保不会在生产环境中加载它。您可以将这一行包装在 if 语句中,例如:

if (process.env.NODE_ENV === 'development') {
  app.use(require('connect-livereload')());
}

这假设您已将名为 NODE_ENV 的环境变量设置为开发、测试或生产,具体取决于您运行应用程序的环境。

【讨论】:

  • 所以我把原来的代码修改了下你的,还是需要添加到第一个if? if ('development' === env || 'test' === env) { if ('development' === env || process.env.NODE_ENV === 'development') { app.use(require('connect-livereload')()); } app.use(express.static(path.join(config.root, '.tmp'))); app.use(express.static(path.join(config.root, 'client'))); app.set('appPath', 'client'); app.use(morgan('dev')); app.use(errorHandler()); // Error handler - has to be last }
  • 另外,在我的 package.json 中,我注意到它不是“依赖项”而是“Devdependencies”,所以我将其更改为“依赖项”,看起来它安装了很多东西,但我认为也有错误。它打印得太多,以至于我再也看不到命令​​行的顶部了。它是否需要是“依赖项”,有没有办法输出它吐出的所有信息?
  • 在使用 Heruko 之前,我还使用了命令grunt serve 来加载我的应用程序,这是否意味着什么特别?
  • 所以看起来你已经有一个 if 声明来执行我的建议,但它没有在生产中为 env 选择正确的值(在 Heroku 上)。如果没有看到您的代码,很难确切地说出发生了什么。 Heroku 不会自动为您设置 NODE_ENV 变量,因此您可以通过从命令行运行 heroku config:set NODE_ENV=production 并坚持使用原始代码来设置它来解决问题。否则,您至少需要发布 app.js 文件的第一部分。
  • 您应该保留您的 package.json 文件原样。 npm 区分您的应用程序在生产中具有的依赖项和仅用于开发的依赖项。所以dependencies 总是被安装,而devDependencies 只安装在你的本地开发环境中。 connect-livereload 是你只在本地想要的东西,所以它属于 devDependencies。
猜你喜欢
  • 2016-09-10
  • 2017-02-09
  • 2013-09-07
  • 2017-12-20
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
  • 2018-08-18
  • 2019-01-21
相关资源
最近更新 更多