在Heroku上部署了create-react-app,但页面空白

时间:2020-08-06 13:55:31

标签: javascript reactjs heroku npm create-react-app

我正在尝试在react上部署heroku应用,但在将其显示在空白的heroku上之后,我也使用buildpack mars/create-react-app创建了此应用

这是我在已部署项目中得到的:

This is what I'm getting on deployed project

这是我的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"
      }
    }

1 个答案:

答案 0 :(得分:0)

此白屏背后的原因是JavaScript文件已加载到浏览器中。

您的Webpack配置中有publicPath设置,用于告诉应用程序其根路径是什么。在我们的示例中,该值为https://www.yourwebsite.com/

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

将这些信息放入package.json文件中,然后将这些行添加到package.json中

"homepage":"your app link"

并再次构建应用程序,它将起作用。