firebase 部署会出现黑页,并显示错误 Uncaught SyntaxError: Unexpected token '<'Understand this error

问题描述 投票:0回答:1

我的网站 neramclasses.com 几天前运行良好。

今天,我尝试更改一些内容并执行 npm run build 并部署到 firebase 托管。

我的构建文件夹已创建,包含所有图像和内容。 当我使用serve运行构建index.html时,它也工作正常。

当我从今天开始使用 firebase 部署将其部署到 firebase 时,页面无法正常工作。没有图像链接、页面链接等。没有任何效果,但我看到所有文件都已上传到 firebase 控制台中的 firebase。

.firebase/hosting.YnVpbGQ.cache 是在部署时创建的,它还显示所有文件

我的 firebase.json 是

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

package.json 中的我的脚本


  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "sitemap": "babel-node ./sitemap-generator.js",
    "predeploy": "npm run sitemap"
  },

我的index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/images/favicon/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="Unlock your architectural dreams with our comprehensive NATA coaching center, serving aspiring architects in Trichy, Chennai, Madurai, Coimbatore, Tiruppur, Pudukkottai, and across Tamil Nadu. Our expert tutors blend online and offline learning, ensuring top-notch preparation for NATA exams. Join us for personalized guidance, extensive study materials, and interactive sessions. Discover your path to success, whether you're in Tamil Nadu or the UAE. Enroll today and sculpt your future in architecture!"
      content="A well Architected NATA Coaching center"
    />
    <meta
      property="og:image"
      content="https://neramclasses.com/images/instagram.jpg"
    />
    <link
      rel="apple-touch-icon"
      href="%PUBLIC_URL%/images/favicon/apple-icon-60x60"
    />
    <!-- Google fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="" />
    <link
      href="https://fonts.googleapis.com/css2?family=Handlee&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&family=Bakbak+One&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Suez+One&display=swap"
      rel="stylesheet"
    />

    <!--
      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>neramClasses - Online / Offline NATA coaching classroom</title>
  </head>
  <body>
    <noscript
      >neram classes is a online/offline NATA coaching center located in chennai
      - Tambaram & Anna Nagar, Trichy, Madurai, Coimbatore, Tiruppur,
      Pudukkottai.Neram Classes is an entrance exam coaching center, primarily
      focusing on architecture exams such as NATA and JEE-MAINs. We are
      committed to giving back to society by providing coaching to students from
      smaller towns and rural areas. Established in 2017 by alumni from
      .....etc.</noscript
    >
    <div id="root"></div>
  </body>
</html>

添加一些部署前后发生的情况的屏幕截图:

在后图中,Javascript 被解析为 html,仅显示索引元数据中的内容

第二张图片

没有文件从 App.js 推送到根目录,也出现错误

我是网络开发的初学者。我尝试了堆栈溢出和 chatgpt 中的每个答案,但没有运气。任何愿意回答的人都请在基本层面上解释一下。据我了解,部署后,chunk.js 文件被视为 html 文件而不是 js。

我试过了

  1. 删除节点模块、json包和npm install
  2. 我尝试重新安装 firebase
  3. 我 npm 构建了很多次,firebase 部署了很多次。
  4. 如果本地构建使用 npxserve -s build 运行良好,但部署将 JavaScript 文件作为 HTML 提供,则问题可能与 Firebase 托管配置或部署过程有关。
reactjs firebase google-cloud-firestore npm-build
1个回答
0
投票

我也遇到了同样的问题。 今天我将 firebase-tools 版本从 13.11.4 更新到 13.12.0(最新),问题解决了。

© www.soinside.com 2019 - 2024. All rights reserved.