我正在Heroku上部署我的React网站。它在本地运行良好,并在运行命令“ heroku local web”。该网站已成功部署,但出现应用程序错误。
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail
在运行heroku日志-tail时,我的日志文件如下所示:
2020-04-20T09:47:52.000000+00:00 app[api]: Build succeeded
2020-04-20T09:47:55.522526+00:00 app[web.1]: ℹ 「wds」: Project is running at https://{some-ip-address}
2020-04-20T09:47:55.523069+00:00 app[web.1]: ℹ 「wds」: webpack output is served from /{filename path}
2020-04-20T09:47:55.523174+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-04-20T09:47:55.523277+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /{filename path}
2020-04-20T09:47:55.523531+00:00 app[web.1]: Starting the development server...
2020-04-20T09:47:55.523534+00:00 app[web.1]:
2020-04-20T09:47:55.631808+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-20T09:48:17.332436+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host={hostname}.herokuapp.com request_id={some_request_id} fwd={ip address} dyno= connect= service= status=503 bytes= protocol=https
什么可能导致失败的原因?我该如何解决?
答案 0 :(得分:1)
您正尝试在Heroku上运行开发服务器,如下所示:
Starting the development server...
您的npm start
任务是什么?您有npm run build
脚本吗?我敢打赌,您的启动脚本会以监视模式启动webpack?
相反,请为您的package.json
尝试以下操作:
{
//...
"scripts": {
"build": "webpack --mode production",
"dev": "webpack --mode development --watch",
"start": "node server.js"
}
}
这假设您正在使用节点服务器,则需要用正在使用的任何服务器或使用Heroku static buildpack来替换start
命令。
如果Heroku看到build
脚本,它将在部署您的应用程序时运行。
如果未使用“ npm start”启动服务器,请确保设置了Procfile
:
web: npm run server