首页 > 解决方案 > 在 Firebase 上部署后 React 应用程序显示空白页面

问题描述

我的 react 应用程序在 localhost 上运行良好,但是当我将它部署到 firebase 托管时,它显示空白页。它显示了这一点: 在此处输入图像描述

我在互联网上查找和堆栈溢出,有很多类似的解决方案,我尝试了所有但对我没有任何作用,这就是我再次询问的原因。我的 firebase.json 文件看起来像这样

    {
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我的 package.json 文件看起来像这样

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.11.0",
    "@material-ui/icons": "^4.9.1",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "firebase": "^7.23.0",
    "firebase-admin": "^9.2.0",
    "react": "^16.13.1",
    "react-currency-format": "^1.0.0",
    "react-dom": "^16.13.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "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"
    ]
  }
}

我应该怎么做才能在 firebase 托管上完美地工作?任何帮助表示赞赏?

标签: reactjsfirebasedeploymentfirebase-hosting

解决方案


推荐阅读