【问题标题】:400 (Bad Request) and cannot find manifest.json400(错误请求)并且找不到 manifest.json
【发布时间】:2019-05-10 20:37:28
【问题描述】:

部署时,heroku 告诉我构建成功,但我得到了 Failed to load resource: the server responded with a status of 400 (Bad Request) 的图标和清单以及 Manifest: Line: 1, column: 1, Unexpected token. Lighthouse 告诉我它根本没有链接到我的 manifest.json。我不确定这些是否相关,如果是这样,我会提出一个新问题。我正在使用带有节点服务器的 Reactjs。

这是我的 server.js

const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 3001;

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

if (process.env.NODE_ENV === "production") {
   app.use(express.static("client/build"));
}

app.get("*", (req, res) => {
  res.sendFile(path.join(__dirname, "./client/public/index.html"));
});


app.listen(PORT, function() {
  console.log(`????  ==> API Server now listening on PORT ${PORT}!`);
});

这是我的 index.html 的头部

<head>
    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, 
    shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <title>React App</title>
</head>

This is my file structure

This is my github repo

如果您需要更多信息,如果这是重复问题,或者这些问题是否无关,请告诉我,以便我采取相应措施。

【问题讨论】:

    标签: javascript reactjs heroku


    【解决方案1】:

    在我的情况下,转到文件 public/index.html

    改变

    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.png" />
    

    <link rel="manifest" href="manifest.json" />
    <link rel="shortcut icon" href="favicon.ico" />
    

    希望能帮到你。

    【讨论】:

      【解决方案2】:

      firebase-hosting 上部署我的react-app 后我遇到了同样的问题

      manifest.jsonfavicon.ico 在 google-chrome DevTools 上的 network 选项卡中提供了 400 Bad Request

      运行firebase init后, 如果您在 firebase 询问 您想使用什么作为公共目录时没有键入 build? (公开) 那么你将不得不去你的根项目文件夹中的firebase.json文件并手动更改主机->“公共”:“构建”

      会是这样的

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

      如果您是deploying react app on firebase,请检查thisthis's 也很有用。

      【讨论】:

        猜你喜欢
        • 2021-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多