由Firebase部署和托管React App时获得空白页

麦克斯特

通过Firebase部署网站域后,进入网站域时我得到一个空白页-我知道我做错了,这是我对运行Firebase Init时覆盖索引/ html文件的选项的回答(是)。

我试图通过各种方法解决它,我已经用我的原始文件替换了firebase生成的build文件夹中的index.html文件,并添加了必需的base和script标签,所以现在至少是空白页面加载和React App名称并登录标签显示它正在加载它。但是内容没有显示。

我曾尝试将firebase.json更改为[“ hosting”:{“ public”:“ dist”,],因为它最初是[“ hosting”:{“ public”:“ build”,]但是,此方法无法正常工作在cmd上收到此错误:错误:指定的公共目录'dist'不存在,无法将主机部署到站点...

相关代码如下,如果您需要更多代码段,请发表评论。

Build / index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="theme-color" content="#000000" />
  <base href="https://contact-form-fba60.firebaseapp.com/">
  <script type="text/javascript" src="https://contact-form-fba60.firebaseapp.com/runtime.a66f828dca56eeb90e02.js"></script>
  <script type="text/javascript" src="https://contact-form-fba60.firebaseapp.com/main.2eb2046276073df361f7.js" ></script>
  <meta name="description" content="Web site created using create-react-app" />
  <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
  <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
  <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
  <title>React App</title>
</head>

<body>
  <noscript>You need to enable JavaScript to run this app.</noscript>
  <div id="root"></div>
  <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
</body>

</html>

firebase.json

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

package.json(不确定是否需要)

{
  "name": "my-website",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.1",
    "@testing-library/user-event": "^12.2.2",
    "animate.css": "^4.1.1",
    "axios": "^0.21.0",
    "bootstrap": "^4.5.3",
    "firebase": "^8.1.1",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-icons": "^3.11.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.0",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "prettier": "2.2.0"
  }
}

将URL重写为index.html时,应选择“ N”。

因此,我建议您重做Firebase初始化。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Rails 4.2和Vagrant:获得空白页,日志中没有任何内容

来自分类Dev

已部署Firebase React.js应用-空白页

来自分类Dev

magento 2:检查侧边栏中是否存在类别时获得空白页

来自分类Dev

登录后仅在Chrome中获得空白页

来自分类Dev

使用Firebase进行仿真时,React应用程序会出现空白页

来自分类Dev

React App生产构建空白只有空白页

来自分类Dev

部署后空白页-带节点的React应用

来自分类Dev

React Firebase Hosting 部署空白页面

来自分类Dev

React Router渲染空白页

来自分类Dev

React Router with Handler 显示空白页

来自分类Dev

尝试同时设置Apache和Django时为空白页

来自分类Dev

单击提交时,Bootstrap 和 PHP 联系表单显示空白页

来自分类Dev

IIS托管的wcf返回空白页

来自分类Dev

Symfony 4,当我打开公共文件夹时,部署后我有空白页

来自分类Dev

如何获得空白标题页?

来自分类Dev

部署后,MVC网站返回空白页

来自分类Dev

MERN应用程序部署到heroku,空白页

来自分类Dev

如何解决空白页?(React初学者)

来自分类Dev

React-MVC4 .Net-空白页

来自分类Dev

Rails 4 content_for和yield显示空白页

来自分类Dev

SUPEE 6788和密码重置(空白页)

来自分类Dev

使用RequireJS和Grunt获取空白页

来自分类Dev

PHP和Mysql返回空白页的问题

来自分类Dev

部署了一个React项目。它只显示空白页而不是项目

来自分类Dev

在执行异步和等待时获得空响应

来自分类Dev

Firebase控制台和Google开发者控制台空白页问题

来自分类Dev

Facebook分享使用php和javascript产生白页/空白页

来自分类Dev

使用Webpack和Babel在网站上部署应用程序时出错(显示空白页)

来自分类Dev

运行构建时为空白页

Related 相关文章

热门标签

归档