reactjs - 如何为成功部署的 React 应用程序修复 Heroku 应用程序错误
问题描述
再会。我已经成功地将我的反应应用程序部署到 Heroku。但是,当我尝试打开时,我的 heroku 日志中出现以下错误:
2020-04-04T11:31:03.263548+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.176.146/
2020-04-04T11:31:03.263914+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-04-04T11:31:03.264020+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-04-04T11:31:03.264096+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-04-04T11:31:03.264274+00:00 app[web.1]: Starting the development server...
2020-04-04T11:31:03.264276+00:00 app[web.1]:
2020-04-04T11:31:03.360569+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-04T14:25:45.432183+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-04T14:25:57.190700+00:00 app[web.1]:
2020-04-04T14:25:57.190727+00:00 app[web.1]: > portfolio@0.1.0 start /app
2020-04-04T14:25:57.190728+00:00 app[web.1]: > react-scripts start
2020-04-04T14:25:57.190728+00:00 app[web.1]:
2020-04-04T14:25:59.253101+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.16.211.122/
2020-04-04T14:25:59.253414+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-04-04T14:25:59.253514+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-04-04T14:25:59.253580+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-04-04T14:25:59.253747+00:00 app[web.1]: Starting the development server...
2020-04-04T14:25:59.253749+00:00 app[web.1]:
2020-04-04T14:25:59.349915+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-04T14:28:20.178274+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kerron-king-portfolio.herokuapp.com request_id=d8f77821-5bd5-4d55-8b95-8fbd37c13c09 fwd="190.213.65.88" dyno= connect= service= status=503 bytes= protocol=https
2020-04-04T14:28:24.241325+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=kerron-king-portfolio.herokuapp.com request_id=c021725e-5389-452d-9601-a7c8018ab331 fwd="190.213.65.88" dyno= connect= service= status=503 bytes= protocol=https
这是一个反应应用程序,它是使用 create-react-app 命令构建的。我没有进行 webpack 编辑,我的 package.json 如下:
{
"name": "portfolio",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.1"
}
}
我的公用文件夹如下:
- index.html
- robots.txt
这些文件的内容是: index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Portfolio</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
机器人.txt:
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
我还有 4 个在项目中使用的图像,它们位于以下目录中:
投资组合/src/imgs
解决此问题的任何帮助将不胜感激。
解决方案
好的,我找到了问题所在。部署时默认的 buildpack 是 node.js 的。我需要使用 create-react-app buildpack(如下所示)。它现在完美运行。
heroku create $APP_NAME --buildpack mars/create-react-app
git push heroku master
heroku open
推荐阅读
- android - 无法使用生物识别管理器打开人脸识别
- android - 如何“重置”片段状态 ANDROID
- docker - 从使用 Meteor Up 部署的 Meteor App 访问主机服务器上的文件
- php - 需要找到孩子在父子关系中存在的最大级别
- excel - VBA If / ElseIf - 编译错误:当前范围内的重复
- javascript - 将 JavaScript 分配给某个 body 类
- python - 模型保存期间自定义注意层返回 AttributeError
- numpy - 从numpy数组中提取所有奇数
- json - 从 JSON 文件加载 JSON 文件,以及 JSON 文件的路径
- python - 在 Pillow 7.1.2 中导入 16 位 TIFF 时出错