在部署React(Node)应用时,出现Heroku错误

4

我在将react应用部署到heroku时遇到了麻烦。我使用以下模板作为起点:https://github.com/reactGo/reactGo,但我将其与我的现有应用程序结合使用。我在本地测试它,运行/构建都很好,但heroku给出了以下错误:

2017-05-10T21:43:07.399992+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-05-10T21:43:07.400522+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-05-10T21:43:07.615526+00:00 heroku[web.1]: Process exited with status 137
2017-05-10T21:43:07.631086+00:00 heroku[web.1]: State changed from starting to crashed
2017-05-10T21:43:07.632321+00:00 heroku[web.1]: State changed from crashed to starting
2017-05-10T21:43:13.661987+00:00 heroku[web.1]: Starting process with command `npm start`
2017-05-10T21:43:16.475503+00:00 app[web.1]:
2017-05-10T21:43:16.475524+00:00 app[web.1]: > react-webpack-node@3.4.1 start /app
2017-05-10T21:43:16.475526+00:00 app[web.1]: > npm run build && cross-env NODE_ENV=production node compiled/server.js
2017-05-10T21:43:16.475526+00:00 app[web.1]:
2017-05-10T21:43:16.944768+00:00 app[web.1]:
2017-05-10T21:43:16.944783+00:00 app[web.1]: > react-webpack-node@3.4.1 build /app
2017-05-10T21:43:16.944787+00:00 app[web.1]: > npm run clean && cross-env NODE_ENV=production npm run webpack -- --env.browser && cross-env NODE_ENV=production npm run webpack -- --env.server
2017-05-10T21:43:16.944788+00:00 app[web.1]:
2017-05-10T21:43:17.328771+00:00 app[web.1]:
2017-05-10T21:43:17.328785+00:00 app[web.1]: > react-webpack-node@3.4.1 clean /app
2017-05-10T21:43:17.328786+00:00 app[web.1]: > rimraf public && rimraf compiled
2017-05-10T21:43:17.328787+00:00 app[web.1]:
2017-05-10T21:43:18.095069+00:00 app[web.1]:
2017-05-10T21:43:18.095084+00:00 app[web.1]: > react-webpack-node@3.4.1 webpack /app
2017-05-10T21:43:18.095085+00:00 app[web.1]: > webpack --colors --display-error-details --config ./webpack/webpack.config.js "--env.browser"
2017-05-10T21:43:18.095086+00:00 app[web.1]:
2017-05-10T21:43:18.812288+00:00 app[web.1]: Running webpack in production mode on browser
2017-05-10T21:43:35.602105+00:00 heroku[run.4255]: Process exited with status 130
2017-05-10T21:43:35.611860+00:00 heroku[run.4255]: State changed from up to complete
2017-05-10T21:43:59.732215+00:00 heroku[web.1]: Process running mem=543M(106.1%)
2017-05-10T21:43:59.732277+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2017-05-10T21:44:13.716290+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-05-10T21:44:13.716376+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-05-10T21:44:13.741192+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2017-05-10T21:44:13.966647+00:00 heroku[web.1]: State changed from starting to crashed
2017-05-10T21:44:13.954005+00:00 heroku[web.1]: Process exited with status 22
2017-05-10T21:44:16.287420+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-spire-17544.herokuapp.com request_id=d4b52f95-a50e-4579-84a0-3b7411726415 fwd="24.207.50.90" dyno= connect= service= status=503 bytes= protocol=https
2017-05-10T21:44:24.777756+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-spire-17544.herokuapp.com request_id=1463bd52-de1d-4351-960d-aedf412c622a fwd="24.207.50.90" dyno= connect= service= status=503 bytes= protocol=https
2017-05-10T21:44:25.694845+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-spire-17544.herokuapp.com request_id=7735e9de-bc4d-4535-b06e-b004b9cc4c8b fwd="24.207.50.90" dyno= connect= service= status=503 bytes= protocol=https
2017-05-10T21:47:47.310866+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-spire-17544.herokuapp.com request_id=de042817-c34a-45e1-88ba-03eaeb78dd19 fwd="24.207.50.90" dyno= connect= service= status=503 bytes= protocol=https
2017-05-10T21:47:48.232781+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-spire-17544.herokuapp.com request_id=8edae68e-5bb8-444e-94e3-cffafb392b15 fwd="24.207.50.90" dyno= connect= service= status=503 bytes= protocol=https

以下是我的尝试,但都没有成功: - 重新启动 Heroku - 验证端口是否动态安装。
有什么建议吗?
2个回答

4

您在启动过程中遇到了R10错误: R10错误(启动超时)-> Web进程无法在启动后的60秒内绑定到$PORT

您可能忘记将服务器绑定到名为PORT的环境变量。您必须在ReactGo模板的某个位置添加以下代码行:app.set('port', (process.env.PORT || 3000));或更直接的方式是:app.listen(process.env.PORT || 3000);

或者

建立过程需要超过60秒,这导致您的动态休眠在应用程序构建之前终止。您需要使用专用的CI工具,例如CircleCI(提供连接器到Heroku),来构建您的应用程序,然后在Heroku上启动它。

R14不是Heroku的关键错误,但会降低性能。如果您在Heroku上作为持续集成平台(如我在您的日志中看到的),则在构建期间可能很容易出现此问题。


我没有更改模板的那部分内容,"app.set('port', (process.env.PORT || 3000));" 这一行仍然存在,"app.listen(app.get('port'));" 也是如此。 - Ryan
好的,我已经添加了另一个可能会导致您的应用程序在启动之前崩溃的潜在陷阱。 - gouroujo

1
您遇到了“错误 R14(超出内存配额)”。 请查看R14 - Memory Quota Exceeded以获取一些可能的提示。 也许您在单个dyno中打包了太多功能? 您的Procfile长什么样,您使用哪些dyno类型?

我的Procfile文件中只有一行 "web: npm start",我使用的是免费的dyno。我测试了使用这个boilerplate模板部署到heroku上是没有问题的,但是当我将这个模板与我现有的应用程序结合使用时,会导致heroku崩溃。但在heroku上运行我的应用程序(与模板结合)却没有问题...? 部署时不应该能够正常工作吗? - Ryan
听起来你的应用程序与样板文件结合在一起可能需要太多的内存,以至于单个免费的动态实例无法平稳地处理。你可能需要查看是什么在使用这么多的内存。 - Yoni Rabinovitch
我有点怀疑,我尝试将所有子组件注释掉并只呈现最外层容器进行部署,但仍然出现这种情况。你知道如何查看 Node 应用程序中使用内存的方式吗? - Ryan

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