node.js - 部署 react ( Node )应用程序时 Heroku 出错

标签 node.js reactjs heroku

我在将 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 -验证端口是动态安装的

有什么建议吗?

最佳答案

启动时出现 R10 错误:错误 R10(启动超时)-> Web 进程在启动后 60 秒内无法绑定(bind)到 $PORT

您应该忘记将您的服务器绑定(bind)到名为 PORT 的环境变量。您必须在某处的 ReactGo 样板中具有以下行:app.set('port', (process.env.PORT || 3000)); 或更直接:app.listen(process .env.PORT || 3000);

构建过程需要 60 多秒才能完成,这会导致您的测功机在您的应用构建之前终止。您需要使用专用的 CI 工具,如 CircleCI(它提供 Heroku 的连接器)来构建您的应用程序,然后在 Heroku 上启动它。

R14 不是 Heroku 中的严重错误,但会降低您的性能。如果您将 Heroku 用作持续集成平台(正如我在您的日志中看到的那样),这很容易在构建期间发生。

关于node.js - 部署 react ( Node )应用程序时 Heroku 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43903320/

相关文章:

node.js - :Sequelize how set returned data order

ios - 完整图像 Assets 未转换为 base64 字符串

ruby-on-rails - 如何在 Heroku 上配置暂存环境?

javascript - 如何在 react-visjs-timeline 中调用方法

ruby-on-rails - Heroku:上传单个未版本化的文件

heroku - 在Heroku中使用Bonsai.io指向同义词文件路径

javascript - ssh2 : Module parse failed: Unexpected character '�'

node.js - sails 政策 - 使用变量

node.js - 无法以 express 方式发布到服务器

reactjs - Redux-saga 从 Action 中获取数据返回 patternOrChannel 未定义