Heroku 上的 React 应用程序
React Application on Heroku
有一个工作的 React 应用程序可以 运行 在本地使用命令:
npm start
但是,在 Heroku 上部署后,我收到一条应用程序错误消息。
申请 URL 是:
https://earth-weather.herokuapp.com/
申请日志如下:
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
分叉的 (public) 存储库位于 GitHub。
感谢您提供的任何帮助。 - 本杰明
根据您的应用程序日志,Starting the development server
行表示应用程序在 development mode
上 运行,这不应该发生,因为它是生产环境。
原因,
根据https://devcenter.heroku.com/changelog-items/370
A Procfile is no longer required to run a Node.js app on Heroku. If no Procfile is present in the root directory of your app during the build process, we will check for a scripts.start entry in your package.json file. If such an entry is present, a default Procfile is generated automatically
$ cat Procfile
web: npm start
在您的存储库中,因为您尚未指定 Procfile。 Heroku 自动生成一个 Procfile,用于在开发时运行您的应用程序。
目前,您的 react-app 被视为常规 node.js 应用程序,因为使用了 node.js buildpack,这是由于根目录中存在 package.json
而自动推断出来的。
要解决此问题,您需要在 Heroku 上使用 create-react-app-buildpack。
参考:https://elements.heroku.com/buildpacks/nhutphuongit/create-react-app-buildpack
有一个工作的 React 应用程序可以 运行 在本地使用命令:
npm start
但是,在 Heroku 上部署后,我收到一条应用程序错误消息。
申请 URL 是:
https://earth-weather.herokuapp.com/
申请日志如下:
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
分叉的 (public) 存储库位于 GitHub。
感谢您提供的任何帮助。 - 本杰明
根据您的应用程序日志,Starting the development server
行表示应用程序在 development mode
上 运行,这不应该发生,因为它是生产环境。
原因,
根据https://devcenter.heroku.com/changelog-items/370
A Procfile is no longer required to run a Node.js app on Heroku. If no Procfile is present in the root directory of your app during the build process, we will check for a scripts.start entry in your package.json file. If such an entry is present, a default Procfile is generated automatically
$ cat Procfile
web: npm start
在您的存储库中,因为您尚未指定 Procfile。 Heroku 自动生成一个 Procfile,用于在开发时运行您的应用程序。
目前,您的 react-app 被视为常规 node.js 应用程序,因为使用了 node.js buildpack,这是由于根目录中存在 package.json
而自动推断出来的。
要解决此问题,您需要在 Heroku 上使用 create-react-app-buildpack。
参考:https://elements.heroku.com/buildpacks/nhutphuongit/create-react-app-buildpack