React 应用程序在本地运行但在 Heroku 上崩溃

Gar*_*hes 1 heroku reactjs

我花了 6 个多小时试图找出为什么它不能在 Heroku 上成功运行。它在本地运行,但是当我部署到 Heroku 时,我得到以下日志,基本上只是说应用程序崩溃了。我安装了 Heroku 的 CLI 并尝试在其中找到更有用的错误,但无济于事。还有其他人有什么想法或建议吗?

\n\n

代码 => https://github.com/ghughes13/react-todo-list

\n\n

https://ghughes-react-todo-list.herokuapp.com/

\n\n
2020-04-05T14:46:31.351885+00:00 app[web.1]: [34m\xe2\x84\xb9[39m [90m\xef\xbd\xa2wds\xef\xbd\xa3[39m: Project is running at http://172.18.176.170/\n2020-04-05T14:46:31.355002+00:00 app[web.1]: [34m\xe2\x84\xb9[39m [90m\xef\xbd\xa2wds\xef\xbd\xa3[39m: webpack output is served from \n2020-04-05T14:46:31.355159+00:00 app[web.1]: [34m\xe2\x84\xb9[39m [90m\xef\xbd\xa2wds\xef\xbd\xa3[39m: Content not from webpack is served from /app/public\n2020-04-05T14:46:31.355252+00:00 app[web.1]: [34m\xe2\x84\xb9[39m [90m\xef\xbd\xa2wds\xef\xbd\xa3[39m: 404s will fallback to /\n2020-04-05T14:46:31.355468+00:00 app[web.1]: Starting the development server...\n2020-04-05T14:46:31.355470+00:00 app[web.1]: \n2020-04-05T14:46:31.498661+00:00 heroku[web.1]: State changed from starting to crashed\n2020-04-05T14:46:33.839876+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ghughes-react-todo-list.herokuapp.com request_id=199836cb-d38a-4941-aee7-fc5e5deba5dc fwd="97.99.41.155" dyno= connect= service= status=503 bytes= protocol=https\n2020-04-05T14:46:34.454912+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ghughes-react-todo-list.herokuapp.com request_id=b905fff4-83bf-4319-801a-c2c4f1d7a4e1 fwd="97.99.41.155" dyno= connect= service= status=503 bytes= protocol=https\n
Run Code Online (Sandbox Code Playgroud)\n\n
  "name": "todo-list",\n  "version": "0.1.0",\n  "private": true,\n  "dependencies": {\n    "@reach/router": "^1.3.3",\n    "axios": "^0.19.2",\n    "mongodb": "^3.5.2",\n    "mongodb-client-encryption": "^1.0.1",\n    "mongoose": "^5.8.11",\n    "reach": "^1.0.1",\n    "react": "^16.9.0",\n    "react-dom": "^16.9.0",\n    "react-scripts": "^3.4.1"\n  },\n  "scripts": {\n    "start": "react-scripts start",\n    "build": "react-scripts build",\n    "test": "react-scripts test",\n    "eject": "react-scripts eject"\n  },\n  "eslintConfig": {\n    "extends": "react-app"\n  },\n  "browserslist": {\n    "production": [\n      ">0.2%",\n      "not dead",\n      "not op_mini all"\n    ],\n    "development": [\n      "last 1 chrome version",\n      "last 1 firefox version",\n      "last 1 safari version"\n    ]\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Raq*_*Bob 5

加勒特给了我关于如何解决这个问题的很好的信息,但没有解释他如何清楚地解决这个问题,我将链接发送到这里,以防你们不想像我一样再挣扎一小时:

如果你有react-app并且有同样的错误,将你的buildpack从基本的heroku/node-js更改为create-react-app-buildpack很可能会修复它:

https://elements.heroku.com/buildpacks/mars/create-react-app-buildpack

在终端/cmd 上:

   heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git#v6.0.0
Run Code Online (Sandbox Code Playgroud)

然后再次推送你的react-app