Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React在Heroku上的应用_Heroku_Create React App - Fatal编程技术网

React在Heroku上的应用

React在Heroku上的应用,heroku,create-react-app,Heroku,Create React App,有一个可以使用以下命令在本地运行的React应用程序: npm启动 但是,在Heroku上部署之后,我收到一条应用程序错误消息。 应用程序URL为: 应用程序日志如下所示: 2021-05-12T08:05:27.430345+00:00 app[web.1]: [34mℹ[39m [90m「wds」[39m: webpack output is served from 2021-05-12T08:05:27.430467+00:00 app[web.1]: [34mℹ[39m [90m「w

有一个可以使用以下命令在本地运行的React应用程序:
npm启动

但是,在Heroku上部署之后,我收到一条应用程序错误消息。 应用程序URL为:

应用程序日志如下所示:

2021-05-12T08:05:27.430345+00:00 app[web.1]: [34mℹ[39m [90m「wds」[39m: webpack output is served from 
2021-05-12T08:05:27.430467+00:00 app[web.1]: [34mℹ[39m [90m「wds」[39m: Content not from webpack is served from /app/public
2021-05-12T08:05:27.430577+00:00 app[web.1]: [34mℹ[39m [90m「wds」[39m: 404s will fallback to /
2021-05-12T08:05:27.430864+00:00 app[web.1]: Starting the development server...
2021-05-12T08:05:27.430866+00:00 app[web.1]: 
2021-05-12T08:05:27.554932+00:00 heroku[web.1]: Process exited with status 0
2021-05-12T08:05:27.631647+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-12T08:05:28.728857+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=earth-weather.herokuapp.com request_id=f067160f-79fc-4336-8488-ded7e7eb5ddb fwd="183.90.36.67" dyno= connect= service= status=503 bytes= protocol=https
2021-05-12T08:05:30.511115+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=earth-weather.herokuapp.com request_id=059ee61d-fe00-4a69-9966-61506da73911 fwd="183.90.36.67" dyno= connect= service= status=503 bytes= protocol=https
2021-05-12T08:05:31.219414+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=earth-weather.herokuapp.com request_id=0f53eee2-39a0-4311-b8a3-62cb9ffcde3c fwd="35.185.241.102" dyno= connect= service= status=503 bytes= protocol=http

分叉(公共)存储库已启用


感谢您提供的任何帮助。-Benjamin

根据您的应用程序日志,启动开发服务器的行
,表示应用程序正在
开发模式下运行,这不应该发生,因为它是一个生产环境

原因是,

在Heroku上运行Node.js应用程序不再需要Procfile。如果在构建过程中应用程序的根目录中没有Procfile,我们将在package.json文件中检查scripts.start条目。如果存在这样的条目,则会自动生成默认的Procfile

在您的存储库中,因为您尚未指定Procfile。Heroku会自动生成一个在开发时运行应用程序的程序文件

目前,您的react应用程序被视为常规的node.js应用程序,因为使用了node.js buildpack,这是由于根目录中存在
package.json
而自动推断的

要解决此问题,您需要在Heroku上使用CreateReact应用程序构建包


请参阅:

您应该在问题中发布相关日志,而不是外部链接。“我收到一条应用程序错误消息”-上面写着什么?错误消息显示:“应用程序中发生错误,您的页面无法服务。”尝试将您的应用程序推送到Vercel或Netlify并检查。感谢您的建议。我尝试部署的应用程序使用API密钥从特定后端服务器()提取数据。因此,Netlify不适用()。您也刚刚尝试了Vercel,但得到了相同的结果(即不成功)。您的API密钥是否存储在
.env
文件中?本地生产构建成功吗?API密钥存储在
apiKeys.js
文件中。本地生产构建成功。您可以从
package.json
&程序文件中共享脚本吗?可以。谢谢你@Jagan Kaartik
$ cat Procfile
web: npm start