heroku 400(错误请求)并且找不到manifest.json

w3nuxt5m  于 2023-01-05  发布在  其他
关注(0)|答案(3)|浏览(138)

部署时,heroku告诉我构建成功,但favicon和manifest得到了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
让我知道如果你需要更多的信息,如果这是一个重复的问题,或者如果这些问题是不相关的,所以我可以采取相应的行动。

ilmyapht

ilmyapht1#

我在firebase-hosting上部署react-app后遇到了同样的问题
manifest.jsonfavicon.ico在谷歌Chrome开发工具的network选项卡中给出了400 Bad Request
运行firebase init后,如果在firebase询问**你想使用什么作为你的公共目录?(public)**时你没有输入build,那么你必须转到你的根项目文件夹中的firebase.json文件并手动更改托管-〉"public":"构建"
会是这样的

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

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

kqlmhetl

kqlmhetl2#

在我的例子中,请转到文件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" />

我希望能有所帮助。

bihw5rsg

bihw5rsg3#

我有这个相同的错误在我的react应用构建,它是由错误的路径manifest.json:

<link rel="manifest" href="%PUBLIC_URL%/manifest.json">

我通过编辑build文件夹中的index.html修复了它:

href="./manifest.json"

href="manifest.json"

相关问题