在Heroku上部署了Create-Reaction-App,但页面为空白 [英] create-react-app is deployed on Heroku but page is blank

查看:35
本文介绍了在Heroku上部署了Create-Reaction-App,但页面为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在heroku上部署react应用程序,但在Heroku上部署它显示空白页面后,我还使用buildpack mars/create-react-app

创建了此应用程序

以下是我对已部署项目的看法:

这是我的package.json文件:

    {
      "name": "covid-19",
      "version": "0.1.0",
      "private": true,
      "homepage": "covid-19-stats-by-anny-v3",
      "dependencies": {
        "@material-ui/core": "^4.11.0",
        "@material-ui/icons": "^4.9.1",
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.5.0",
        "@testing-library/user-event": "^7.2.1",
        "axios": "^0.19.2",
        "express": "^4.17.1",
        "fetch": "^1.1.0",
        "gh-pages": "^3.1.0",
        "material-table": "^1.65.0",
        "mui-datatables": "^3.3.1",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-social-icons": "^4.1.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "predeploy": "npm run build",
        "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": {
        "react-scripts": "^3.4.1"
      }
    }

推荐答案

此白屏背后的原因是将脚本文件加载到浏览器中。

在您的webpack配置中有Public Path设置,用于告诉应用程序它的根路径是什么。在我们的示例中,这将是https://www.yourwebsite.com/

如果设置正确,它将基于该URL的上述链接,您的应用程序将按预期加载。

将此信息放入Package.json文件在Package.json中的版本之后添加这些行

"homepage":"your app link"

并再次生成应用程序,它将起作用。

这篇关于在Heroku上部署了Create-Reaction-App,但页面为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆